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

340c241a97cdc541d3f4b8c57ada068d

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.

#include<iostream.h>        
#include<stdio.h>
#include<conio.h>
int main()
{
FILE *k;
char c;
k=fopen("c:\\fff.txt","r");
c=getc(k);
while(c!=EOF)
{
 cout<<c;
 c=getc(k);
 }
 getch();
 fclose(k);
 return 0;
}

please help me. thanks

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.
thanks.

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

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.