Advertisement
pbin_

labile2

Dec 17th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #define N 20
  6.  
  7. int main(){
  8.  
  9. FILE *ft;
  10. char name1[N];
  11. char frase[N];
  12. int cont=0;
  13. long int pos;
  14.  
  15.  
  16. printf("Inserire nome file di testo:");
  17. gets(name1);
  18.  
  19. ft=fopen(name1, "a");
  20.  
  21. do{
  22.  
  23. pos=ftell(ft);
  24. printf("\n\nInserire una frase(max. 20 caratteri):\n\n");
  25. gets(frase);
  26.  
  27.  
  28. if((strcmp(frase,"indietro")==1) && (cont<2){
  29.  
  30. cont++;
  31. fseek(ft, strlen(frase), SEEK_CUR);
  32. gets(frase);
  33. fprintf(ft, "%s\n", frase);}
  34.  
  35. else if((strcmp(frase,"indietro")==1) && (cont==2){
  36.  
  37. fprintf(ft, "%s\n", frase);
  38. cont--;
  39. }
  40.  
  41. else{
  42.  
  43. fprintf(ft, "%s\n", frase);
  44. }
  45.  
  46. }while( strcmp(frase,"fine")==0);
  47.  
  48.  
  49. fprintf(ft,"%s\n", frase);
  50.  
  51. return 0;
  52. }
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement