2021年4月10日星期六

Problem scanning strings with spaces in C

I have to scan a string with spaces so I can do somethings with it in this case moving the string n chars to the right or to the left. For example:

If I give n = 1, the string

house  

becomes:

ehous  

But the input can also be a string with spaces like, n being the same:

yellow house  

becomes:

eyellow hous  

So to scan the string im doing this:

char text[166];  scanf("%d %[^\n]%*c", &n, &text);  

And everything works great, but now the I submitted the program I get this error:

src.c: In function 'main':  src.c:30:26: error: format '%[^   ' expects argument of type 'char *', but argument 3 has type 'char (*)[166]' [-Werror=format=]   30 |             scanf("%d %[^\n]%*c", &nVezes, &texto);      |                       ~~~^~                ~~~~~~      |                          |                 |      |                          char *            char (*)[166]  

What can I solve this? Also I can't use these libraries string.h, strings.h, and stdlib.h.

Every bit of help is appreciated.

https://stackoverflow.com/questions/67040446/problem-scanning-strings-with-spaces-in-c April 11, 2021 at 08:30AM

没有评论:

发表评论