Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #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 = fopen(filename, "w");
- if (fp) {
- 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];
- fp = fopen(filename, "r");
- if (fp) {
- 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;
- }
Add Comment
Please, Sign In to add comment