Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- int main()
- {
- const char *filename = "myfile.txt";
- const char *mode = "w";
- FILE *p = fopen(filename, mode);
- if (p == NULL)
- {
- printf("Error! Cannot open file: %s\n", filename);
- return 1;
- }
- char text[] = "Hello!Hello!Hello!Hello!Hello!";
- for (int i=0; i<strlen(text); i++)
- {
- fseek(p, 0, SEEK_SET);
- fputc(text[i], p);
- }
- /*
- int elem = fwrite(text, strlen(text), 1, p);
- if (elem == 0)
- {
- printf("Cannot write to file!\n");
- }
- */
- fclose(p);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement