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

C/C++ Q/A
[1239] Re:왜 에러가 나나여??
남병철.레조 [lezo] 1635 읽음    2002-09-23 11:50

안녕하세요? 레조입니다.

예전에 C로 프로그래밍을 할때는 선언이전에 어떤 작업을 하면 컴파일이 않되었습니다.
그 때문에 c와 cpp의 차이로 컴파일 방식이 C 또는 C++로 차이가 생기고 이렇게되면서
선언 이전에 어떤 처리가 있으면 C방식에서는 오류가 나게됩니다.

즉, clrscr();을 선언문 아래로 빼내면 두 타입에서 문제없이 작동하게 됩니다.
:     char *name,*num;                <-----------   여기서.에러
:     int kor,eng,math,sci,phy;       <-------------  여기서에러
:     float total1,total2,avg1,avg2;   <---------  여기서 에러
:     clrscr();

clrscr()을 아래로 내려보세요.
선언시에는 화면에 영향을 주지 않으니 그 이후부터 처리해도 결과에는 차이가
없습니다.



선녀 님이 쓰신 글 :
: **.c 하고 **.cpp 하고 다른 가봐여..
: 똑같은 소스를 c로 저장해서 컴파일 하면 에러가 나고 cpp로 저장하면 에러 없이 잘 돌아가니..
: 이 소스가 그렇던데.. 왜 그런지..설명좀 부탁해여..
:
: Declaration is not allowed here
: Declaration is not allowed here
: Declaration is not allowed here
:
: 이렇게 에러 코드가 나오네여..
:
: #include <stdio.h>
: #include <conio.h>
: void main(void)
: {
:     clrscr();
:     char *name,*num;                <-----------   여기서.에러
:     int kor,eng,math,sci,phy;       <-------------  여기서에러
:     float total1,total2,avg1,avg2;   <---------  여기서 에러
:     gotoxy(40,5);    printf("score");
:     gotoxy(23,7);   printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
:     gotoxy(25,9);
:     printf("input name : ");    scanf("%s",name);
:     gotoxy(25,10);
:     printf("input number : ");         scanf("%s",num);
:     gotoxy(16,11);
:     printf("input First kor, eng, math, sci, phy :");
:     scanf("%d %d %d %d %d",&kor,&eng,&math,&sci,&phy);
:     total1=kor+eng+math+sci+phy;
:     avg1=total1/5;
:     gotoxy(16,12);
:     printf("input Second kor, eng, math, sci, phy :");
:     scanf("%d %d %d %d %d",&kor,&eng,&math,&sci,&phy);
:     total2=kor+eng+math+sci+phy;
:     avg2=total2/5;
:     gotoxy(23,14);  printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
:
:     gotoxy(25,15);
:     printf("name : %s\t",name);    printf("number : %s\n",num);
:     gotoxy(25,16);
:     printf("First total : %.0f , average : %.2f",total1,avg1);
:     gotoxy(25,17);
:     printf("Second total : %.0f , average : %.2f",total2,avg2);
:     gotoxy(23,19);
:     printf("=======================================");
:     gotoxy(25,21);
:     printf("total sum : %.0f , average : %.2f",total1+total2,(avg1+avg2)/2);
:     getch();
: }
:
:
:

+ -

관련 글 리스트
1236 왜 에러가 나나여?? 선녀 1536 2002/09/23
1239     Re:왜 에러가 나나여?? 남병철.레조 1635 2002/09/23
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.