I'm trying to read data from a file. I have the following loop. The data in the file is a matrix. The problem I'm having is I'd like to access each element, but &line[0]
does not index by character in the line, it prints the whole thing. So the whole row of the matrix is stored in the first index somehow...
I'm having trouble getting it out. I tried copying it to m, but that seems to only give me the first element only.
Lets say for example, &line[0]
is "1 2 3", how do I loop through this so I can store it in an array?
FILE *fptr;
char * line = NULL;
size_t len = 0;
ssize_t read;
int linenum = 1;
while ((read = getline(&line, &len, fptr)) != -1) {
printf("Retrieved line of length %zu:\n", read);
printf("%s", line);
//matrix size information
if (linenum==1){
char m[100];
char n[100];
printf("------\n");
printf("%s", &line[0]);
//strcpy(m, &line[0]);
}
linenum++;
}