Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main(void)
- {
- char opr;
- int besk;
- char *name_file = malloc(sizeof(char) * 64);
- char *buffer_text = malloc(sizeof(char) * 512);
- FILE *file;
- besk = 0;
- printf("1 - write file, 2 - read file\n");
- do
- {
- printf("What you need: ");
- scanf("%c", &opr);
- switch (opr)
- {
- case '1':
- printf("Enter name for your file: ");
- scanf("%s", name_file);
- printf("Enter some text for your file: ");
- scanf("%s", buffer_text);
- file = fopen(name_file, "w");
- fprintf(file, "%s", buffer_text);
- fclose(file);
- free(name_file);
- free(buffer_text);
- break;
- case '2':
- printf("Enter name for your file: ");
- scanf("%s", name_file);
- file = fopen(name_file, "r");
- fgets(buffer_text, 512, file);
- fclose(file);
- printf("Text from %s: %s", name_file, buffer_text);
- free(name_file);
- free(buffer_text);
- break;
- case '0':
- besk = 1;
- break;
- //default:
- //printf("Unknown command! Try again!\n");
- }
- }
- while (besk != 1);
- name_file = NULL;
- buffer_text = NULL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement