编译打印一个字符串函数给出错误信息 - C.

Yuv*_*val 4 c string printf

我想在C中编写一个简单的main函数,它接收两行字符串输入并在屏幕上打印它们.这是我写的代码:

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;
}
Run Code Online (Sandbox Code Playgroud)

当我尝试编译时,我收到此错误消息:

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]
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助

md5*_*md5 8

你使用%S格式,而strings(char*)的格式是%s.

printf("%s - %s\n", a, b);
Run Code Online (Sandbox Code Playgroud)