Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define MAX_LEN 32
- main(){
- int sum=0, n;
- char string[MAX_LEN];
- FILE * fp, * fo;
- ((fp=fopen("file.txt", "r"))!=NULL)?:(exit(1));
- ((fo=fopen("output.txt", "w"))!=NULL)?:(exit(1));
- while(feof(fp)==0)
- if((fscanf(fp, "%d", &n))==1){
- sum+=n;
- fprintf(fo, "%d\t", n);
- }
- else
- fscanf(fp, "%s", string);
- fprintf(fo, "\nLa somma e' %d\n", sum);
- fclose(fp);
- fclose(fo);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement