1

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;
}
4

1 に答える 1

4

関数を参照するstrtokか、strtok_r

http://www.cplusplus.com/reference/cstring/strtok/?kw=strtok

于 2013-04-11T19:44:08.403 に答える