2013-04-11 120 views
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; 
} 
+0

http://stackoverflow.com/questions/9210528/split-string-with-delimiters-in-c – 2013-04-11 19:44:57

回答