I have this simple code in C to scan and print a string with a whitespace:
#include <stdio.h>
#include <string.h>
int main()
{
char myName[50];
printf("Enter your name: ");
scanf("%[^\n]s", &myName);
printf("Your name is: %s", myName);
return 0;
}
The compiler (gcc, part of the command line tools that come with Xcode on my mac) is returning this error:
name.c: In function ‘main’:
name.c:7: warning: format ‘%[^
’ expects type ‘char *’, but argument 2 has type ‘char (*)[50]’
name.c:7: warning: format ‘%[^
’ expects type ‘char *’, but argument 2 has type ‘char (*)[50]’
What's the problem here?
NOTE: I am required to use scanf. No fgets for me :(