Hi there, I am having trivial problem in reading a simple file (see below).
This file is not a list of numbers or list of strings, but is a combination of the two.
All is fine when I read it line by line and assign the numbers to a certain variable by using fscanf, but when I try to do the same for the strings, I obtain a bus error.
I hope someone can help;
thank you in advanced,
CFD
My code looks as it follows, and the input file is the next:
input.txt
Code to read it:Code:problem_type problem_name 24.5 53.1 44.0
Code:FILE *file_ID; const char *problem[2]; // After reading the file this variable would be something like this: // problem[0] = "problem_type" // problem[1] = "problem_name" int i,j,k=0; float, x,y,z; file_ID = fopen("input.txt", "r"); //Read the content of the input file: fgets(problem[0],..4,..file_ID); fgets(problem[1],..4,..file_ID); fscanf(file_ID, "%f\n", &x); fscanf(file_ID, "%f\n", &y); fscanf(file_ID, "%f\n", &z);



LinkBack URL
About LinkBacks



I used to be an adventurer like you... then I took an arrow to the knee.