본문 바로가기

프로그램/C언어 1000제149

C언어 113제] C언어 콘서트 CHAPTER 12 Programming 5 파일에 저장하기 p489 출처 : 반크_세계유산 고인돌 참고풀이] //Dev-C++ 5.11로 작업함. #include #include //exit() struct Employee{ char name[20]; int age; int pay; }; int main(void) { FILE *fp1; struct Employee em; //파일을 쓰기 모드로 연다. if ((fp1 = fopen("employee.txt", "w")) == NULL) { fprintf(stderr, "employee파일을 열 수 없습니다.\n"); exit(1); } printf("직원 이름 : "); fscanf(stdin, "%s", em.name); printf("나이 : "); fscanf(stdin, "%d", &em.age); printf(.. 2022. 1. 25.
C언어 112제] C언어 콘서트 CHAPTER 12 Programming 4 두파일을 비교하기 p489 출처 : 반크_세계유산 고인돌 참고파일] //Dev-C++ 5.11로 작업함. #include #include //exit() #include //strcmp() int main(void) { FILE *fp1, *fp2; char file1[100], file2[100]; char StrLine1[255],StrLine2[255]; int c; int chk1, chk2; //두 파일의 끝여부 파악 변수 printf("첫번째 파일 이름 : "); scanf("%s", file1); printf("두번째 파일 이름 : "); scanf("%s", file2); // 첫 번째 파일을 읽기 모드로 연다. if ((fp1 = fopen(file1, "r")) == NULL) { fprintf(stderr, ".. 2022. 1. 25.
C언어 111제] C언어 콘서트 CHAPTER 12 Programming 3 라인의 개수 구하기 p488 출처 : 반크_세계유산 고인돌 참고풀이] //Dev-C++ 5.11로 작업함. #include #include //exit() #include //strlen(), strcmp() int main(void) { FILE *fp1; char file1[100]; char StrLine[255]; int c; int chk;//파일의 끝 여부 파악변수 //파일을 읽기 모드로 연다. if ((fp1 = fopen("fseek1.c", "r")) == NULL) { fprintf(stderr, "원본 파일 %s을 열 수 없습니다.\n", file1); exit(1); } //fp1에서 한 라인씩 읽어서 문자열이 있으면 카운트한다. c=0; while (chk=fgets(StrLine,sizeof(StrLine).. 2022. 1. 24.
C언어 110제] c언어 콘서트 CHAPTER 12 Programming 2 정수의 개수, 합계, 평균 구하시오. p488 출처 : 반크_세계유산 고인돌 참고풀이] //Dev-C++ 5.11로 작업함. #include #include //exit(), atoi() #include //strlen() int main(void) { FILE *fp1; char file1[100]; char StrLine[255]; int i,j;//반복변수 int c,n;//정수의 개수, 전체 자료 개수 변수 int Sum;//정수의 합 변수 int chk;//파일의 끝, 정수 여부 파악변수 //파일을 읽기 모드로 연다. if ((fp1 = fopen("numbers.txt", "r")) == NULL) { fprintf(stderr, "원본 파일 %s을 열 수 없습니다.\n", file1); exit(1); } //fp1에서 한 라인씩 읽어서.. 2022. 1. 24.
C언어 109제] C언어 콘서트 CHAPTER 12 Programming 1 파일의 내용 읽어서 화면에 출력하기 p488 출처 : 반크_세계유산 고인돌 참고풀이] //Dev-C++ 5.11로 작업함. #include #include //exit() int main(void) { FILE *fp1; char file1[100]; char StrLine[255]; int c; int chk;//파일의 끝 여부 파악변수 printf("파일 이름을 입력하시오 : "); scanf("%s", file1); //파일을 읽기 모드로 연다. if ((fp1 = fopen(file1, "r")) == NULL) { fprintf(stderr, "원본 파일 %s을 열 수 없습니다.\n", file1); exit(1); } //fp1에서 한 라인씩 읽어서 출력한다. c=0; while (chk=fgets(StrLine,sizeof(StrLin.. 2022. 1. 21.
C언어 108제] C언어 콘서트 CHAPTER 12 p469 도전문제 특수문자 제거 출처 : 반크_세계유산 고인돌 참고풀이] #define _CRT_SECURE_NO_WARNINGS #include #include //exit(), tolower() int main(void) { FILE *fp1, *fp2; char file1[100], file2[100]; printf("원본 파일 이름: "); scanf("%s", file1); printf("복사 파일 이름: "); scanf("%s", file2); // 첫 번째 파일을 읽기 모드로 연다. if ((fp1 = fopen(file1, "r")) == NULL) { fprintf(stderr, "원본 파일 %s을 열 수 없습니다.\n", file1); exit(1); } // 두 번째 파일을 쓰기 모드로 연다. if ((fp2 = .. 2022. 1. 19.
C언어 107제] C언어 콘서트 CHAPTER 11 Programming 7 열거형 사용하기 p456 출처 : 반크_세계유산 고인돌 참고풀이] //Dev-C++ 5.11로 작업함. #include #include //srand(), rand() #include //time() int main() { enum Game { kawee, bawee, bo}; int N; //player 변수 int C; //컴퓨터 변수 int chk; //결과승부 변수 //무작위 값을 산출하기 위한 초가값 설정 srand(time(NULL)); printf("가위(0), 바위(1), 보(2)를 입력하세요 : "); scanf("%d",&N); C=rand()%3; if(N==C) chk=0; else if(N==kawee) if(C==bo) chk=1; else if(C==bawee)chk=-1; else if(N==bawe.. 2022. 1. 19.
C언어 106제] C언어 콘서트 CHAPTER 11 Programming 6 재고를 검색하기 p456 출처 : 반크_세계유산 고인돌 참고풀이] //Dev-C++ 5.11로 작업함. #include #include //system() #include //strcmp() typedef struct PIMS { //Product Inventory Management System char product[20]; //상품명 변수 int price; //가격 변수 int count; //개수 변수 int total; //총재고액 변수 }pims; int main() { pims N[3];//상품재고 변수 char Search[20];//검색 변수 int i; int chk;//검색여부 파악 변수 //재고 자료를 입력합니다. for(i=0;i 2022. 1. 18.
C언어 105제] C언어 콘서트 CHAPTER 11 Programming 5 나이가 20이상 30 이하인 직원 출력하기 p456 출처 : 반크_세계유산 고인돌 참고풀이] //Dev-C++ 5.11로 작업함. #include typedef struct employee { int number; char name[20]; char phone[12]; int age; }em; int main() { em N[10]={ {220103001,"홍길동1","01012341234",20}, {220103002,"홍길동2","01012341235",22}, {220103003,"홍길동3","01012341236",33}, {220103004,"홍길동4","01012341237",32}, {220103005,"홍길동5","01012341238",34}, {220103006,"홍길동6","01012341239",31}, {220103007,"홍길동7.. 2022. 1. 18.
C언어 104제] C언어 콘서트 CHAPTER 11 Programming 4 두시간 사이의 차이를 계산하기 p455 출처 : 반크_세계유산 고인돌 참고풀이] //Dev-C++ 5.11로 작업함. #include typedef struct Time { int hour; int minute; int second; }uTime; uTime diff_time(uTime a, uTime b) { uTime result; result.second = b.second - a.second; result.minute = b.minute - a.minute; result.hour = b.hour - a.hour; if(result.second 2022. 1. 17.
C언어 103제] C언어 콘서트 CHAPTER 11 Programming 3 복소수 더하기 p455 출처 : 반크_가상독도전시관 참고풀이] //Dev-C++ 5.11로 작업함. #include typedef struct Complex { double x; double y; }Comp; Comp add_complex(Comp a, Comp b) { Comp result; result.x=a.x+b.x; result.y=a.y+b.y; return result; } int main() { Comp N1,N2;//복소수값을 입력할 변수 Comp R;//결과값을 넣을 변수 //자료를 입력합니다. printf("첫번째 복소수를 입력하시오 : "); scanf("%lf%lf",&N1.x,&N1.y); printf("두번째 복소수를 입력하시오 : "); scanf("%lf%lf",&N2.x,&N2.y); //처리부.. 2022. 1. 17.
C언어 102제] C언어 콘서트 CHAPTER 11 Programming 2 구조체 활용하여 이메일 표현하기 p455 출처 : 반크_가상독도전시관 참고풀이] //Dev-C++ 5.11로 작업함. #include #include //strlen() struct Email { char title[50]; //제목 char receiver[50];//수신자 char sender[50];//발신자 char contents[2000];//내용 char date[9];//날짜 int rank;//우선순위 }; void Line() { int i; for(i=1;i 2022. 1. 14.
반응형