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

C/C++ Q/A
[5186] Re:왜 출력이...
행인 [] 1403 읽음    2005-07-27 21:56
scanf("%s %s ", rec.fname, rec.lname );
에서 마지막 space 를 제거해주세요..
scanf("%s %s", rec.fname, rec.lname );

그 이유는.... VC 로... Disassembly 해 보면...
scanf("%s %s ", rec.fname, rec.lname );
00401042   push        offset _rec+22h (0042ae82)
00401047   push        offset _rec+4 (0042ae64)
0040104C   push        offset string "%s %s " (00425060) <- 인자
00401051   call        scanf (004010d0) <- 해당 scanf procedure call
00401056   add         esp,0Ch

scanf:
004010D0   push        ebp
004010D1   mov         ebp,esp
004010D3   sub         esp,8
004010D6   push        ebx
004010D7   push        esi
004010D8   push        edi
004010D9   lea         eax,[ebp+0Ch]
004010DC   mov         dword ptr [arglist],eax
004010DF   cmp         dword ptr [format],0   <---- 요기!  NULL 값이 아니라 space 가 들어가 있어 오동작하게 됨
004010E3   jne         scanf+33h (00401103)

하여간 위와같은 이유로 오동작하네여~

미니 님이 쓰신 글 :
: #include<stdio.h>
:
:
:    struct data{
:      int amount;
:      char  fname[30];
:      char  lname[30];
:    }rec;
:
:  main()
:  {
:    printf("Enter the donor's first and last name,\n");
:    printf("separated by a space: ");
:    scanf("%s %s ", rec.fname, rec.lname );
:
:    printf("\nEnter the donation amount: ");
:    scanf("%d",&rec.amount);
:
:    printf("\nDonor %s %s gave $%d.\n",rec.fname,rec.lname,rec.amount);
:
:    return 0;
:  }
:
: 보시다시피 fname,lname을 쓰기 요구하는 함수 다음에 amount값을 요청하는 printf문이 떠야되는데
: 이를 생무시하고 숫자값 쓰기 요구하는 scanf문이 뜬후에야 히한하게
: "Enter the donation amount" 이 출력이 됩니다. 왜 순서가 엉키는 건가요?

+ -

관련 글 리스트
5185 왜 출력이... 미니 1289 2005/07/27
5186     Re:왜 출력이... 행인 1403 2005/07/27
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.