I have a text file that reads as follows:
5f6
2c6
4g6
I'd like to obtain the numbers from that textfile (as chars then convert them to integers using strtol()
I have the code:
char *ptr;
char *ptr2;
char *ptr3;
char *ptr4; //redundant but attempting these before I'm doing `char * []`
char buf[100];
while (fgets(buf,100,file) )
ptr = strtok(buf,"f");
ptr2 = strtok(NULL," ");
ptr3 = strtok(NULL, "f");
ptr4 = strtok(NULL, " ");
however, the program seg faults but compiles. How would I go about doing this more efficiently (By a method that doesn't seg fault)?
Aucun commentaire:
Enregistrer un commentaire