본문 바로가기
반응형

전체 글186

30_파일IO서식기반 #include struct student_t{ char name[20]; int kor; int eng; int mat; int total; float aver; char grad; }; void fun_inputjumsu(struct student_t * stulist, int size); void fun_printstudent(const struct student_t * stulist, int size); void fun_input_sum(struct student_t * stulist, int size); void fun_input_aver(struct student_t * stulist, int size); void fun_printresult(const struct student_t * stu.. 2018. 4. 28.
29_파일복사 #include //file1 을 file2에 복사 // read write void filecpy(const char* file1, const char * file2) { char ch; FILE *in, *out; in = fopen(file1, "r"); out = fopen(file2, "w"); if (in == NULL || out == NULL) { printf("파일 열기 실패\n"); return; } //========================================== while ((ch = getc(in)) != EOF) { putc(ch, out); } //=========================================== fclose(in); fclose(ou.. 2018. 4. 28.
28_파일IO문자전용 //문자 전용 IO #include #include "test.h" /* 1. 파일 열기 2. 파일 사용................ 3. 파일 닫기 */ //파일 포인터는 R/W 할 경우 자동으로 다음 바이트로 //이동한다. void fun_read() { char ch; int i; FILE * in = fopen("aaa.txt", "r"); if (in == NULL) { printf("파일 열기 실패\n"); return; } //========================================== // ch = fgetc(in); // printf("%c", ch); //stdout // fprintf(stdout, "%c", ch); for (int i = 0; i < 26; i++).. 2018. 4. 28.
27_파일IO기본코드 #include /* 1. 파일 열기 2. 파일 사용................ 3. 파일 닫기 */ /* void fun_read() { FILE * in = fopen("aaa.txt", "r"); if (in == NULL) { printf("파일 열기 실패\n"); return; } //========================================== //=========================================== fclose(in); } void fun_write() { FILE * in = fopen("aaa.txt", "a"); if (in == NULL) { printf("파일 열기 실패\n"); return; } //=======================.. 2018. 4. 28.
26_typedef사용법 #include typedef struct tagb{ int b; }b; typedef struct taga a; struct taga { int a; }; int main() { struct taga a1; a a2; struct tagb b1; b b2; return 0; } 2018. 4. 28.
25_구조체실습, 비트필드, 공용체 #include struct list{ char name[20]; char sex; int age; }; // inp 함수 구현, 사용자로부터 이름, 성별, 나이를 입력 받아 저장하는 기능 void inp1(struct list * pman ); void main(){ struct list man; inp1(&man); printf("\n Name Sex Age\n"); printf("-------------------------\n"); printf("%s %c %d\n", man.name, man.sex, man.age); } void inp1(struct list * pman) { //1번째 방법 : 임시변수를 선언해서 입력받은 후 // 대입연산을 통해 원본의 값에 저장하는 방법 //char nam.. 2018. 4. 28.
24_구조체포인터및인자전달 #include #include // 문자열 h typedef struct tagmember member; struct tagmember { char name[20]; //이름 char gender; //성별 int age; //나이 }; void foo(member m); void woo(member *pm); void goo(char *n, char g, int a); void hoo(char *n, char *g, int *a); int main() { member mem1 = { "홍길동", 'm', 10 }; //1. 구조체 값 전달 foo(mem1); //2. 구조체 주소 전달 woo(&mem1); //3. 구조체 맴버 전달 goo(mem1.name, mem1.gender, mem1.age);.. 2018. 4. 28.
23_구조체배열 #include #include // 문자열 h //생성된 타입명 //1) struct tagmember //2) member typedef struct tagmember member; struct tagmember { char name[20]; //이름 char gender; //성별 int age; //나이 }; /* //구조체 배열 int main() { member mem[2] = { { "abc", 'm', 10 }, { "ABC", 'f', 20 } }; printf("첫번째 사람의 이름 : %s\n", mem[0].name); printf("첫번째 사람의 성별 : %c\n", mem[0].gender); printf("첫번째 사람의 나이 : %d\n", mem[0].age); printf(".. 2018. 4. 28.
22_구조체1 #include //step1) 구조체가 없을 때 코드 구현 /* void fun_today(int *y, int *m, int *d); void fun_print(int y, int m, int d); int main(int argc, char*argv[]) { int year; int month; int day; fun_today(&year, &month, &day); fun_print(year, month, day); return 0; } void fun_today(int *y, int *m, int *d) { *y = 2016; *m = 7; *d = 4; } void fun_print(int y, int m, int d) { printf("%d/%d/%d\n", y, m, d); } */ //s.. 2018. 4. 28.
반응형