C   69
file c
Guest on 11th February 2023 01:22:43 PM


  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(void) {
  5.     FILE * input = fopen("input", "r");
  6. //    FILE * output = fopen("outptut", "w");
  7.     FILE * output = fopen("outptut", "a");
  8.     char string[80];
  9.     int a;
  10.     char c;
  11.     int sum = 0;
  12.     while ((c = getc(input)) != EOF) {
  13.         //fprintf(output, "%c", c);
  14.         putc(c, output);
  15.     }
  16.     fputs("\nhi there\n", output);
  17.     if (feof(input)) {
  18.         printf("reached end of file\n");
  19.     }
  20.     fclose(input);
  21.     input = fopen("input", "r");
  22.     if (input == NULL) {
  23.         printf("ooops\n");
  24.     }
  25.     while (fgets(string, 80, input) != NULL) {
  26.         fputs(string, output);
  27.     }
  28.     fclose(input);
  29.     input = fopen("numbers", "r");
  30.     while(fgets(string, 80, input) != NULL) {
  31.         sum+= atoi(string);
  32.     }
  33.     printf("sum is %d\n", sum);
  34.     fclose(input);
  35.     fclose(output);
  36.     return 0;
  37. }

Raw Paste

Login or Register to edit or fork this paste. It's free.