i want to write a simple main function in C that receive two line of string input and prints them on the screen. this is the code i wrote:
int main()
{
char a[100];
char b[100];
printf("Enter the first string:\n");
fgets(a,100,stdin);
printf("Enter the second string:\n");
fgets(b,100,stdin);
printf("\n\n THE FIRST STRING IS: %S\n\n THE SECOND STRING IS:%S",a, b);
return 0;
}
and when i try to compile, i get this error message:
gcc -g -Wall PN52.c -o myprog
PN52.c: In function ‘main’:
PN52.c:12:2: warning: format ‘%S’ expects argument of type ‘wchar_t *’, but argument 2 has type ‘char *’ [-Wformat]
PN52.c:12:2: warning: format ‘%S’ expects argument of type ‘wchar_t *’, but argument 3 has type ‘char *’ [-Wformat]
Thanks for helping
You use %S
format, whereas the format for strings (char*
) is %s
.
printf("%s - %s\n", a, b);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With