본문 바로가기
반응형

01.Bit 단기/C32

32_난수 중복없이 출력 void main() { int arr[10]; srand(time(NULL)); for (int i = 0; i < 10; i++) { arr[i] = rand() % 10; printf("%d ", arr[i]); } printf("\n"); for (int i = 0; i < 10; i++) { for (int j = 0; j < i; j++) { while (arr[i] == arr[j]) { arr[i] = rand() % 10; j = 0; } } } for (int i = 0; i < 10; i++) printf("%d ", arr[i]); } 2021. 11. 29.
31_파일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.
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.
반응형