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;
}
Knoblauch
  • 5,740
  • 6
  • 33
  • 81
  • 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,272
  • 13
  • 19