프로그래밍/C 44

80컬럼 컨솔에 19단표 출력하기 예제 for C and Ch

다음은 Java용으로 만들어 둔 소스파일 TestForForApp.java(참조: 80컬럼 컨솔에 19단표 출력하기 예제 for Java )를 C용 소스로 고쳐본 것이다. 스트링을 처리하고 전달하기 위해 메모리 할당(allocation)과 해제(free)를 하면서 동적 메모리(dynamic memory)를 이용하고 있다. 소스 변경 없이 Ch 로도 실행시킬 수 있다. /* * Filename: testForFor.c * * Compile: cl testForFor.c * Execute: testForFor * * Execute without compiling: ch testForFor.c * * Date: 2008. 3. 3. */ #include #include #include // 매개변수 dan으로..

프로그래밍/C 2008.03.03

(최대공약수 구하기) while... 반복문 예제 for C

소스 파일명: testWhile.c /* * Filename: testWhile.c * * Purpose: Example using the while loop syntax * while .... * * Compile: cl testWhile.c * * Execute: testWhile -200 300 */ #include #include // 사용법 표시 void printUsage() { printf("Using: testWhile [integer1] [integer2]\n"); printf("This finds the greatest common divisor of the given two integers.\n"); } int main(int argc, char *argv[]) { long val1,..

프로그래밍/C 2008.02.21

if...else... 조건문 사용 예제 for C

소스 파일명: testIf.c #include #include // 사용법 표시 함수 void printUsing() { printf("Using: testIf [number]\n"); printf("This determines whether the number is positive or not.\n"); } // main 함수 int main(int argc, char *argv[]) { float val; if (argc != 2) { printUsing(); exit(1); return 1; } // 명령행 인자의 스트링을 가져와서 // 배정밀도 부동소수점수로 변환하여 // 변수 val에 저장한다. val = atof(argv[1]); // 변수 val에 저장된 값이 양수인지 음수인지 0인지를 //..

프로그래밍/C 2008.02.19

맹령행 인자 처리 예제 for C

소스 파일명: testArguments.c #include // printf 함수 사용을 위해 #include // atof 함수 사용을 위해 // argc는 명령행 인자 개수, argv는 명령행 인자 문자열의 배열 int main(int argc, char *argv[]) { int i; double sum = 0.0; // 초기화 // 명령행 인자(command-line argument) 개수 출력 printf("Count of arguments: %d\n", argc); for (i = 0; i < argc; i++) { // 스트링을 배정밀도 부동소수점수로 변환하여 누적 sum += atof(argv[i]); } // 배정밀도 부동소수점수 값을 %g로 출력 printf("The sum of arg..

프로그래밍/C 2008.02.18