69,382
社区成员
发帖
与我相关
我的任务
分享
int sscanf(const char *buffer,const char *format[,argument ]...);
但你看楼主传的参数呢?第一个貌似就不对……
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char c2fbuy[]="Apple 4.89 626\nBanana 3.4 500\nCashew 0.94 310\nDurian 0.39 429\nEggfruit 3.43 141\n\
Feijoa 0.66 957\nGuarana 0.5 43\nHuito 0.63 452\nIndianFig 44.16 105\nJackfruit 1.3 1739\n";
double p;
int q;
char str[20];
char *sp;
int i=0;
sp = strtok(c2fbuy, " \n");
do {
switch(i)
{
case 0:
strcpy(str,sp);
break;
case 1:
p=atof(sp);
break;
case 2:
q=atoi(sp);
printf("str=%s\tp=%lf\tq=%d\n",str,p,q); //这里输出一组数据
break;
}
i++;
i%=3;
sp=strtok(NULL," \n");
} while (sp!=NULL);
system("pause");
return 0;
}