Yuval
Yuval

Reputation: 1771

compile printing a string function give error message - C

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

Upvotes: 4

Views: 533

Answers (3)

sushant goel
sushant goel

Reputation: 831

just replace %S by %s as C is case-sensitive that's why you have to take care of these things

Upvotes: 0

Replace uppercase %S by lowercase %s in printf format string.

Upvotes: 3

md5
md5

Reputation: 23737

You use %S format, whereas the format for strings (char*) is %s.

printf("%s - %s\n", a, b);

Upvotes: 8

Related Questions