Advertisement
octavio123

Untitled

Mar 30th, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. int main()
  4. {
  5. char ch, chr;
  6. FILE* fpw, *fpr;
  7. fpw = fopen("D:\\prgfiles\\data1.txt", "w");
  8.  
  9. if (fpw == NULL)
  10. {
  11. printf("Error");
  12. exit(1);
  13. }
  14.  
  15. printf("Enter any character: ");
  16. scanf("%c", &ch);
  17. fprintf(fpw, "%c", ch);
  18. fclose(fpw);
  19.  
  20. if ((fpr = fopen("D:\\prgfiles\\data1.txt", "r")) == NULL)
  21. {
  22. printf("Error! opening file");
  23. return(1);
  24.  
  25. }
  26. chr = getc(fpr);
  27.  
  28. printf("This is the character entered by the user = %c \n", ch);
  29. printf("And this is the character read from the file = %c \n", chr);
  30.  
  31. fclose(fpr);
  32.  
  33.  
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement