1

I have a program that read File in C. Now I want to put the strings divide by space into an array. How do I do it?

#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;
}
Felipe
  • 7,013
  • 8
  • 44
  • 102
  • http://stackoverflow.com/questions/9210528/split-string-with-delimiters-in-c –  Apr 11 '13 at 19:44

1 Answers1

4

Have a look at the function strtok or strtok_r

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

K Scott Piel
  • 4,320
  • 14
  • 19