Dear all,
I am trying to read a list of string from text file and put it into an array.
Could anyone tell me, how to split that string to array.
Here's my text file....
text.txt
a b
1 2 4
2 3 1
*3 1 3
*4 4 4
I want to show that looks like this,
a
b
1
2
4
2
3
1
*3
1
3
*4
4
4
My code:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int i=0;
char* string[100];
char line[100];
FILE *file;
file = fopen("text.txt", "r");
while(fgets(line, sizeof line, file)!=NULL)
printf("%s", line);
string[i]=line;
i++;
}
for (i=0 ; i<4; i++) {
printf("\n%s", string[i]);
}
fclose(file);
return 0;
}
my code only show like this.
a b
1 2 4
2 3 1
*3 1 3
*4 4 4
Can anyone tell me, where i have to fix my code. Plz help me.
thanks in advance.