0
我有一個程序,它讀取C中的文件。現在我想把字符串按空格分成一個數組。我該怎麼做?在C中讀取文件並拆分字符串
#include <stdio.h>
int main()
{
char line[30];
char names[100][20];
int sizes[100];
int i = 0;
FILE *fp;
fp = fopen("in.txt", "rt");
if(fp == NULL)
{
printf("cannot open file\n");
return 0;
}
while(fgets(line, sizeof(line), fp) != NULL)
{
printf(line);
i++;
}
fclose(fp);
return 0;
}
http://stackoverflow.com/questions/9210528/split-string-with-delimiters-in-c – 2013-04-11 19:44:57