Guest User

C programming - segmentation fault (core dump)

a guest
Jun 8th, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.44 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void print(FILE*, int);
  5.  
  6. int main(int argc, char** argv)
  7. {
  8.     FILE *output;
  9.     if ((output = fopen("output.txt", "w")) == NULL)
  10.     {
  11.         printf("cannot open the file input\n");
  12.         exit(EXIT_FAILURE);
  13.     }
  14.  
  15.     int data = 1;
  16.     do
  17.     {
  18.         scanf("%d", &data);
  19.         print(output, data);
  20.     } while (data > 0);
  21.  
  22.     fclose(output);
  23.     return 0;
  24. }
  25. void print(FILE* output, int data)
  26. {
  27.     fprintf(output, "%d\n", data);
  28. }
Add Comment
Please, Sign In to add comment