Sunday, December 31, 2017

file io Maximum number C

file io Maximum number C




file io - Maximum number "C" -

im begginer in programming , have task. need find maximum number file in.txt content: 2,5,4,6,7,10 , write file out.txt. language c. problems are:

im not in programing , in english(so if u seek explane me in english language dont think ill understand every word) in end there should max number on da screen, shows me first number

its not first theme here , every time moderator give link can read text , find answer, @ priblem(1) there much text , cannot tranlate in answers(themes) help me please im noob/ have code:

#include <conio.h> #include <stdio.h> main() { int n, max; file *f; f = fopen("in.txt", "r"); // open file file *g; g = fopen("out.txt", "w"); // open file fscanf(f, "%d", &max); while (feof(f)) { fscanf(f, "%d", &n); if (max < n) max = n; } printf("max=%d", max); // show result on screen fprintf(g, "%d", max); // set result out.txt fclose(f); fclose(g); }

check see if fopens succeed. check if scanf succeed. scanf fail @ eof , drop out of loops

#include <stdio.h> int main () { int n,max; file*f; f=fopen("in.txt","r"); //open file if ( f == null) { // check if fopen failed printf ( "could not open in.txt "); homecoming 1; } file*g; g=fopen("out.txt","w"); //open file if ( g == null) { fclose ( f); printf ( "could not open out.txt "); homecoming 1; } if ( ( fscanf(f,"%d",&max)) == 1) // read int max. if success homecoming 1 { while( ( fscanf(f,"%d",&n)) == 1) // read int n. if success homecoming 1 { if(max<n) { max=n; } } printf("max=%d",max);//show result on screen fprintf(g,"%d",max); //put result out.txt } fclose(f); fclose(g); homecoming 0; }

c file-io

go to link download
download
alternative link download

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.