C语言如何实现从txt中读取特定数据?

2024-11-23 08:44:20
推荐回答(1个)
回答(1):

#include
#include
#include
void main()
{
char *pcTmp = NULL;
char szBuf[] = "abcdef 123456";
char seps[] = " ";
char ch[20];
int num;

pcTmp = strtok(szBuf,seps);
if( NULL != pcTmp )
{
strcpy(ch, pcTmp);
printf("ch is %s\n", ch);
}
pcTmp = strtok(NULL,seps);
if( NULL != pcTmp )
{
num = atoi(pcTmp);
printf("num is %d\n", num);
}
system("pause");
}