You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
590 B
37 lines
590 B
2 years ago
|
#include <stdio.h>
|
||
|
#include <string.h>
|
||
|
|
||
|
int main( int argc, char *argv[] ){
|
||
|
if( argc == 2 ) {
|
||
|
|
||
|
char buffer[10] = {'\0'};
|
||
|
FILE *fp=fopen(argv[1], "r");
|
||
|
unsigned int value = 0, total=0, largest=0;
|
||
|
|
||
|
while (!feof (fp)){
|
||
|
fgets(buffer, 10, fp);
|
||
|
//fscanf(fp, "%d\n", &value);
|
||
|
|
||
|
|
||
|
if (strlen(buffer) == 1){
|
||
|
if ( total > largest ) largest=total;
|
||
|
total=0;
|
||
|
} else {
|
||
|
sscanf(buffer,"%d\n",&value);
|
||
|
total+=value;
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
printf("The largest is %d\n", largest);
|
||
|
fclose(fp);
|
||
|
|
||
|
|
||
|
|
||
|
return 0;
|
||
|
} else {
|
||
|
printf("You need to provide a file\n");
|
||
|
return 1;
|
||
|
}
|
||
|
}
|