关于sscanf()问题
#include <stdio.h>
#include <string.h>
int main()
{
const char str[] = "hello,world ";
char Buf[10] = {0};
sscanf(str, "%*s%s ",Buf); //这段的%*s怎么把hello world全屏蔽了?
printf( "%s ",Buf);
getch();
return 0;
}
我想输出world,改怎么写?谢谢!:)
[解决办法]
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
const char str[] = "world ";
char Buf[10] = {0};
sscanf(str, "%s ",Buf);
printf( "%s ",Buf);
system( "pause ");
return 0;
}
[解决办法]
错了,上面的解释是正对printf的,关于sscanf的描述如下:
An asterisk (*) following the percent sign suppresses assignment of the next input field, which is interpreted as a field of the specified type. The field is scanned but not stored.
这个地方错在对于字符串的分隔字符,字符串的分隔字符可以为:空格,TAB,回车。
改为下面就可以了:
#include <CONIO.H>
#include <stdio.h>
#include <string.h>
int main()
{
const char str[] = "hello, world ";
char Buf[10] = {0};
sscanf(str, "%*s%s ", Buf); //这段的%*s怎么把hello world全屏蔽了?
printf( "%s ",Buf);
getch();
return 0;
}