Created
June 14, 2016 16:51
-
-
Save LusainKim/f7cca14fe1fa36c46c1c4f8d4decef0e to your computer and use it in GitHub Desktop.
C FileStream에서 구조체 단위로 읽기 예제
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
typedef struct{ | |
char name[20]; | |
char phone[30]; | |
char email[100]; | |
}phone; | |
void ReadPhone(char* path, phone *p) | |
{ | |
FILE* pf = fopen(path, "rt"); | |
fread(p, sizeof(phone), 1, pf); | |
fclose(pf); | |
} | |
void WritePhone(char* path, phone *p) | |
{ | |
FILE* pf = fopen(path, "wt"); | |
fwrite(p, sizeof(phone), 1, pf); | |
fclose(pf); | |
} | |
int main() | |
{ | |
phone writeTest; | |
sprintf(writeTest.name, "Lusain.Kim"); | |
sprintf(writeTest.phone, "010-1124-5521"); | |
sprintf(writeTest.email, "[email protected]"); | |
WritePhone("C_LoadStruct.txt", &writeTest); | |
phone readTest; | |
ReadPhone("C_LoadStruct.txt", &readTest); | |
printf("name : %s\nphone : %s\nemail : %s\n", readTest.name, readTest.phone, readTest.email); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment