Advertisement
Guest User

writer

a guest
Dec 6th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main()
  5. {
  6. const char *filename = "myfile.txt";
  7. const char *mode = "w";
  8.  
  9. FILE *p = fopen(filename, mode);
  10.  
  11. if (p == NULL)
  12. {
  13. printf("Error! Cannot open file: %s\n", filename);
  14. return 1;
  15. }
  16.  
  17. char text[] = "Hello!Hello!Hello!Hello!Hello!";
  18.  
  19. for (int i=0; i<strlen(text); i++)
  20. {
  21. fseek(p, 0, SEEK_SET);
  22. fputc(text[i], p);
  23. }
  24.  
  25. /*
  26. int elem = fwrite(text, strlen(text), 1, p);
  27.  
  28. if (elem == 0)
  29. {
  30. printf("Cannot write to file!\n");
  31. }
  32. */
  33.  
  34. fclose(p);
  35.  
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement