Advertisement
VSZM

Szöveges fájlok kezelése C

May 15th, 2014
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3.  
  4.  
  5. int main()
  6. {
  7.     int a, b;
  8.     FILE* input, *output;
  9.     input = fopen("in.txt","r");
  10.     output = fopen("out.txt","w");
  11.    
  12.     if(input == NULL || output == NULL) // Ellenőrizzük, hogy sikerült-e megnyitni a fájlt.
  13.     {
  14.         printf("Could not open one of the files!\n");
  15.         return -1; 
  16.     }
  17.  
  18.    
  19.     while(fscanf(input, "%d %d", &a, &b) != EOF)// End of file-ig olvasunk be.
  20.     {
  21.         int szorzo;
  22.  
  23.         scanf("%d", &szorzo);
  24.  
  25.         fprintf(output,"%d\n", (a+b) * szorzo);
  26.     }
  27.  
  28.     fclose(input);
  29.     fclose(output);
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement