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
#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; }
double lineHandler(char s);
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 }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)