using while and getline to split data of a input file and assign different columns to different variables in C -


how split line read file in c , assign values different columns different variables?

i have .txt file in each line contains 4 integer values separated tab. have store first value in variable , second value in variable , b third value in variable, c.

and pass a, b , c arguments function.

and read next line file , doing same above until end of file. trying use getline.

input file has kind of data:

1   2   3   4    7   4   3   2 3   2   5   4 2   98  876 989 

in 1 iteration

i want

 a=1  b=2  c=3  int r=func(a,b,c)  //some code based on value of r, such writing file. 

now reading next line a=7 b=4 c=3

again function calling. q1. how split data?

q2. how assign different variables?

but not able come satisfactory solution. me in please?

thanks :)

to rad data variables directly file can use,

fscanf(file,"%d %d %d",a,b,c); 

your input file has 4 numbers need neglect can use,

while(fscanf(file,"%d %d %d %d\n",a,b,c,d)==4) {   r=func(a,b,c);  //some code using value of r } 

you can use code similar this


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -