I am a beginner
I am using with CORSIKA software. cosika's outputs are text files with 8 or 7 column and more than 2000 row(like matrix) .
Arrays of this matrix are number in Scientific notation like fallowing image


I want to read data in 7th column and calculate some parameters like average, maximum, minimum in one column.

I have this code to read and display text file but i dont know how use numbers and calculate some parameters.

int main()
FILE *k;
char c;
 return 0;

please help me. thanks

Attachments sample1.jpg 428.42 KB

why are you reading the file one character at a time? It would be a lot easier to read the entire line with fgets() then extract the number from the column you want.

thanks for your reply
I am not pro!
please guide me more and write Code.

Are you supposed to do this in C++ or C? The code you posted is C, but you posted in c++ forum.

I'm not going to write your whole program for you, but this is how to read one line at a time. If the column you want is always the last word in the line then you could call strrchr() to find the last space. Otherwise if the may be more columns in the line you will need to find the first 7 spaces in a loop.

char line[80];
while( fgets(line,sizeof(line),fin) != NULL)
   // now get pointer to the 7th word in line and convert it to integer

This article has been dead for over six months. Start a new discussion instead.