Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <wchar.h>
- #include <locale.h>
- #include <io.h>
- #include <fcntl.h>
- #include <stdlib.h>
- int main() {
- char message[] = "hello world";
- char filename[] = "aboba.txt";
- FILE* fp;
- if(fopen_s(&fp, &filename, "w") == 0) {
- if (fputs(message, fp) == EOF) {
- perror("WRITE FILE ERROR");
- return 3;
- };
- if (fclose(fp) == EOF) {
- perror("CLOSE FILE ERROR");
- return 2;
- }
- }
- else {
- perror("OPEN FILE ERROR");
- return 1;
- }
- char buffer[256];
- if (fopen_s(&fp, filename, "r") == 0) {
- if (fgets(buffer, 256, fp) == EOF) {
- perror("READ FILE ERROR");
- return 4;
- }
- if (fclose(fp) == EOF) {
- perror("CLOSE FILE ERROR");
- return 2;
- }
- }
- else {
- perror("OPEN FILE ERROR");
- return 1;
- }
- printf("%s", buffer);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement