Turbo-C
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
터보-C 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
Lua 게시판
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C/C++ Q/A
[1446] 김백일님 죄송한데요 STL 이라는것이 무엇인가요?(냉무)
김경래 [necle] 1529 읽음    2002-10-30 08:38
김백일 님이 쓰신 글 :
: 김경래 님이 쓰신 글 :
: : 밑의 프로그램에서 정렬하는부분에서...
: : 제가 돌리니까 결과가 제대로 안나오는데요
: : 어떻게 하면 제대로 나올까요?
:
: 정렬은 그렇게 간단하게 구현되는 게 아닙니다.
: 최소한 이중 for루프를 돌려야 하죠.
:
: : 고수님 잘 부탁드립니다.
:
: 고수틱(?)한 방법을 보여드리죠.
: STL의 sort 알고리듬을 사용한 방법입니다.
:
: : ------------------------
: : #include <stdio.h>
: : #include <stdlib.h>
: : #include <string.h>
:   #include <algorithm>
:
: : #define MAXSTRING 25
: :
: : void Print_func(int p_number);
: : void Fileopen_func(int p_number);
: : void sort_func(int p_number);
: :
: : char amstr1[MAXSTRING];
: : struct data{
: :     char name[MAXSTRING];
: :     char phone[MAXSTRING];
: :     int age;
: : };
: : struct data list[100];
: : struct data buffer;
: :
: : main()
: : {
: :
: :     int ctr,p_number;
: :     char f_panbul,s_panbul;
: :     printf("\n========주소록=========\n");
: :     printf(" 몇명을 입력할껀지 결정하시요:");
: :     scanf("%d",&p_number);
: :     fflush(stdin);
: :     for(ctr=0;ctr<p_number;ctr++)
: :     {
: :         printf("\n %d 번째 사람의 이름을 입력하세요:",ctr);
: :         gets(list[ctr].name);
: :         printf("\n %d 번째 사람의 전화번호를 입력하세요:",ctr);
: :         gets(list[ctr].phone);
: :         printf("\n %d 번째 사람의 나이를 입력하세요:",ctr);
: :         scanf("%d",&list[ctr].age);
: :         fflush(stdin);
: :     }
: :     printf("데이터를 알파벳순으로 정렬 하시겠습니까?:(Y/N)");
: :     scanf("%c",&s_panbul);
: :     if(s_panbul=='Y'||s_panbul=='y')
: :     {
: :         sort_func(p_number);
: :     }
: :     fflush(stdin);
: :
: :
: :
: :     printf("파일에 기록하시겠습니까?:(Y/N)");
: :     scanf("%c",&f_panbul);
: :     if(f_panbul=='Y'||f_panbul=='y')
: :     {
: :         Fileopen_func(p_number);
: :     }else if(f_panbul=='N'||f_panbul=='n')
: :     {
: :         Print_func(p_number);
: :     }
: :     return 0;
: : }
: :
: : void Fileopen_func(int p_number)
: : {
: : FILE *fh;//파일 핸들러
: :     int result,ctr;
: :     char filename[20];
: :     fflush(stdin);
: :     printf("저장할 파일 이름을 입력하세요:");
: :     gets(filename);
: :     if(NULL==(fh=fopen(filename,"a")))
: :     {
: :         printf("파일열기에 실패하였습니다.\n");
: :         exit(-1);
: :     }
: :     else{
: :         printf("파일을 열었습니다.");
: :     }
: :     for(ctr=0;ctr<p_number;ctr++)
: :     {
: :         fprintf(fh,"%s \n %s \n %d\n",list[ctr].name,list[ctr].phone,list[ctr].age);
: :     }
: :     printf("\n\n==>>입력하신 모든 자료를 파일에 저장하였습니다.<<==\n");
: :     if(result=fclose(fh))
: :     {
: :         printf("파일을 닫는데 실패하였습니다.\n");
: :     }
: :     else{
: :         printf(" 파일을 성공적으로 닫았습니다.\n");
: :     }
: : }
: : void Print_func(int p_number)
: : {
: :     int ctr;
: :         for(ctr=0;ctr<p_number;ctr++)
: :     {
: :         printf("%d번\n \t이름:%s \n \t전화:%s \n \t나이:%d\n",ctr,list[ctr].name,list[ctr].phone,list[ctr].age);
: :     }
: : }
: : void sort_func(int p_number)
: : {
:     struct comp_list {
:       bool operator() (const data& x, const data& y)
:       {
:         return strcmp(x.name, y.name) < 0;
:       }
:     }
:     std::sort(&list[0], &list[p_number], comp_list());
:     // 또는 std::sort(list, list + p_number, comp_list());
: : }

+ -

관련 글 리스트
1443 질문이 있어요 김경래 1308 2002/10/29
1444     STL로 하면... 김백일 1458 2002/10/29
1446         김백일님 죄송한데요 STL 이라는것이 무엇인가요?(냉무) 김경래 1529 2002/10/30
1449             FAQ과 Tip'N Tricks를 참고하세요. (냉무) 김백일 1325 2002/10/30
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.