您的位置:首页 > 编程语言 > C语言/C++

C语言字符串拆分,打开关闭文件

2010-12-20 14:24 225 查看
#include<stdio.h>
#include<string.h>
void main()
{
FILE *stream;
stream = fopen("EMA.txt", "r");
if(!stream)
{
printf("open file error");
return 0;
}
char num[4000][100];
char SysStockCode[4000][9];
char StockCode[4000][6];
char BourseNo[4000][2];
char values[4000][15];
char tempTotal[50] = "\0";
int i=0;
char seps[] = ",";
char star[] = ".";
while(fgets(tempTotal,100,stream))
{
int count =0;
char *token;
tempTotal[strlen(tempTotal)-1]='\0';//ɾ³ý×îºóµÄ»Ø³µ×Ö·û
strcpy(num[i],tempTotal);
token = strtok( tempTotal, seps );

while( token != NULL )
{
if(count%3==0)strcpy(SysStockCode[i], token);
else if(count%3==2)strcpy(values[i], token);
token = strtok( NULL, seps );
count++;
}

char *wordToken;
char tempCode[9]= "\0";
strcpy(tempCode,SysStockCode[i]);
wordToken = strtok( tempCode, star );
strcpy(StockCode[i],wordToken);
wordToken = strtok( NULL, star);
strcpy(BourseNo[i],wordToken);
delete wordToken;
//printf("All:%s,SysStockCode:%s,StockCode:%s,BourseNo:%s,values:%s\n",num[i],SysStockCode[i],StockCode[i],BourseNo[i],values[i]);
i++;
}
printf("%d",i);
fclose(stream);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐