I am trying to read two numbers from a text file. I used strtok
, and the delimiter is " "
. The text file (named data.txt) file has only two numbers, the line is "3 5"
. But the program crashes... any help is appreciated.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
FILE *data;
data = fopen("data.txt", "r");
int m, n;
char *line, *number;
while(!feof(data))
{
fscanf(data, "%s", line);
number = strtok(line, " ");
m = atoi(number);
number = strtok(NULL, " ");
n = atoi(number);
}
}