将带有空格的字符串扫描到wchar_t中

时间:2018-12-06 13:36:11

标签: c

我需要扫描wchar_t的字符串。输入中可以有空格,我要扫描直到换行。

为了扫描wchar_t的字符串,我将使用占位符%ls。问题是,这不包括空格。我尝试使用%[^ \ n]进行扫描,但这会发出有关尝试将char扫描到wchar_t的警告,并给出损坏的输出。

这是我的代码段:

wchar_t addressInput[ADDRESS_MAX];
printf("\nPlease enter your street address, to get distance to articles.\n");
scanf(" %[^\n]", addressInput);
printf("%ls", addressInput);

当前,这不打印。我通过调试器检查了addressInput指针,它或多或少地破坏了数据。

0 个答案:

没有答案
相关问题