SHOW:
|
|
- or go back to the newest paste.
| 1 | /* | |
| 2 | * To change this license header, choose License Headers in Project Properties. | |
| 3 | * To change this template file, choose Tools | Templates | |
| 4 | * and open the template in the editor. | |
| 5 | */ | |
| 6 | ||
| 7 | - | /* |
| 7 | + | |
| 8 | * File: main.c | |
| 9 | * Author: NgT | |
| 10 | * | |
| 11 | * Created on February 22, 2016, 10:16 AM | |
| 12 | */ | |
| 13 | ||
| 14 | #include <stdio.h> | |
| 15 | #include <stdlib.h> | |
| 16 | #include <ctype.h> | |
| 17 | #include <string.h> | |
| 18 | //#define TRUE 1; | |
| 19 | //#define FALSE 0; | |
| 20 | - | * |
| 20 | + | |
| 21 | * | |
| 22 | - | void Writefile(char* pFileName, char* pContent) {
|
| 22 | + | |
| 23 | void WriteFile(char* pFileName, char* pContent) {
| |
| 24 | int length = 0; | |
| 25 | ||
| 26 | FILE* f = fopen(pFileName, "a"); | |
| 27 | fflush(stdin); | |
| 28 | do {
| |
| 29 | gets(pContent); | |
| 30 | length = strlen(pContent); | |
| 31 | if (length > 0) {
| |
| 32 | fputs(pContent, f); | |
| 33 | } | |
| 34 | } while (length > 0); | |
| 35 | fclose(f); | |
| 36 | } | |
| 37 | - | char* ReadFile(char* pFileName) {
|
| 37 | + | |
| 38 | - | char c; |
| 38 | + | void ReadFile(char* pFileName) {
|
| 39 | char c; | |
| 40 | FILE* f = fopen(pFileName, "r"); | |
| 41 | while ((c = fgetc(f)) != EOF) | |
| 42 | putchar(c); | |
| 43 | - | return 1; |
| 43 | + | |
| 44 | } | |
| 45 | ||
| 46 | - | main() {
|
| 46 | + | int main() {
|
| 47 | char filename[10], content[100]; | |
| 48 | printf("Enter file to save content: ");
| |
| 49 | gets(filename); | |
| 50 | printf("Enter content: ");
| |
| 51 | gets(content); | |
| 52 | ||
| 53 | - | Writefile(filename, content); |
| 53 | + | WriteFile(filename, content); |
| 54 | printf("File content : \n");
| |
| 55 | - | ReadFile(filename); |
| 55 | + | ReadFile(filename); |
| 56 | return 0; | |
| 57 | } |