Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to read from a file which contains interger ,
 I want to compare the line and print the line with highest value .


I will appreciate if you can show me the few step with code ?
looking forward to hear from you

@CHILL60
@JERON1
@RICHARD DEEMING
@RICHARD MACCUTCHAN


What I have tried:

#include <stdio.h>


#include <stdlib.h>

char lineHandler(s);

int main()
{

int count  =  1  ;
char  store_output[100]   ;
char store_each_line[100]  ;
FILE *patht  = fopen("inputNumber.txt", "r");
char myText[100];

// Use a while loop together with the get line function to read the file line by line

  while (! feof(patht)) {

        fgets(myText, 100, patht);

   // Output the text from the file

char  cal_rec  =   lineHandler(myText)  ;
store_output[count]  = cal_rec  ;

//store each line

store_each_line[count]   =  myText  ;

count++;
  }

  // Close the file

  fclose(patht);

// the calculation  here

int max_get[2];
int count_e   = 0;
for(count_e = 0; count_e > sizeof(store_output) / sizeof(store_output[0]); count_e++)
{
if(max_get[0]  <  store_output[count_e]   && max_get[0]  !=  store_output[count_e] ){
max_get[0]   =   store_output[count_e];
max_get[1]   =  count_e;

}


}


printf("the highest is  %s", store_each_line[max_get[1]]);
}













char lineHandler(s)
{

//array just for calcualtion

printf(" %s", s);
double  arr[3];

	strtok(s, " ");
char word;
int count_pos = 0 
;
	while (s >> word) {
         arr[count_pos] = word;

        //push it into an array file  here not print

		count_pos++;
	}

double  calt   = (arr[0] * arr[0] )  +  arr[1]  +  arr[2];

    return calt;
}
Posted
Updated 23-Jun-21 22:08pm
v3
Comments
Richard MacCutchan 21-Jun-21 8:48am    
You should reformat your code to remove all the unnecessary blank lines, and use standard indentation, so it is at least readable.

You also need to explain what error you get and where it occurs.
Richard Deeming 21-Jun-21 8:49am    
If you want someone to help you fix an error, then you need to tell us what the error is.

Click the green "Improve question" link and update your question to include the full details of the error you are getting.
CHill60 21-Jun-21 11:57am    
Word to the wise - treat compiler warnings as if they are errors and fix them before trying to run your program. For example you have declared
double lineHandler(char s);
but when you call it you are passing it a pointer to a char array
obafemi Davprince 21-Jun-21 12:03pm    
I tried to change the data type still getting the same error
CHill60 21-Jun-21 12:12pm    
There was more than one warning produced when I compiled your code. Fix them all, starting with the first one, then recompile, then fix the next first one, and so on until you get a clean compilation.
Don't just randomly change one line - did you also change the body of the function or just the declaration?

I had follow CHILL60 instruction is working fine but not yet getting my result.

Here is what I want to work on.

I read from a file which contains interger , I want to compare the line and print the line with highest value .


I will appreciate if you can show me the few step with code ?

@CHILL60
@JERON1
@RICHARD DEEMING
@RICHARD MACCUTCHAN
 
Share this answer
 
Comments
Richard Deeming 24-Jun-21 4:02am    
If you want to update your question to add more information, click the green "Improve question" link and update your question.

DO NOT post your update as a "solution" to your question!
Richard MacCutchan 24-Jun-21 4:32am    
The solution is to go back to your course notes and study them in detail. You are mixing data types at random and missing declarations. For example:
char lineHandler(s) // you need to tell the function what type 's' is expected to be.
{

// no point in even looking at the rest of the code 

double  calt   = (arr[0] * arr[0] )  +  arr[1]  +  arr[2];

    return calt; // your declaration says this function returns a char, but you are trying to return a double
}
can you help me figure it out ?
 
Share this answer
 
Comments
jeron1 21-Jun-21 13:02pm    
This is not a solution.
obafemi Davprince 22-Jun-21 2:52am    
what are the solution. jeron1
jeron1 22-Jun-21 10:27am    
Maybe, if you explain what the error is. Have you followed CHill60's suggestions?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900