본문 바로가기
반응형

프로그래머의 길/C & C++93

디렉토리 관련 함수 #include #include #include int main() { char dir[256]; int ret = 0; FILE *fp; ret = chdir("C:\\test"); // test라는 디렉토리가 있으면 0, 없으면 -1을 리턴함. if(ret == -1) // test라는 디렉토리가 없을경우 mkdir("C:\\test"); // test 디렉토리 생성 else { // test라는 디렉토리가 있을경우 chdir("C:\\test"); // test 디렉토리로 이동 fp = fopen("test.txt","wt"); // test.txt파일 open if(fp){ fprintf(fp,"This is a test file."); fclose(fp); } } return 0; } 폴더가 있.. 2007. 4. 9.
이진 트리로 구현한 문자열, 숫자 정렬 소스 문자열 정렬 #include #include #include struct tree { char info[20]; int cnt; struct tree * left,*right; }*root; FILE *in,*out; void insert(char *); void inorder(struct tree *); void main(){ char value[20]; in =fopen("word.dat","r"); out = fopen("freq.out","w"); while(fscanf(in,"%s",value),(strcmp(value,"/*")!=0)) insert(value); fprintf(out,"\tWords\t\t\tFrequencies\n"); inorder(root); fclose(in); fcl.. 2007. 3. 30.
const의 정확한 이해 const는 변수를 상수로 만든다. 예를들면, const double TAX=0.12 // 수정 불가 하지만, 포인터 변수를 상수화 시키는 것은 특별하다. int a=0; const int *ap = &a; *ap = 20; // 포인터 변수를 상수화 시킬 경우 포인터 자체가 고정되는것이 // 아니라 해당되는 값을 고정시킨다. 즉, 이 문장은 에러다. // 포인터의 값은 변경 가능하다. 2007. 3. 26.
조건부 컴파일 전처리 명령어 조건부 컴파일 지시어(#if, #elif, #else, #ifdef, #ifndef, #endif) 조건부 컴파일 지시어는 지정된 조건에 의하여 프로그램 파일의 특정한 부분을 컴파일하거나 컴파일하지 않게 하는 지시어이다. 조건부 컴파일 지시어의 의미를 알아 보자. 조건부 컴파일 지시어 의 미 #if 조건 #if 다음에 조건이 맞으면 #if와 #endif 사이의 문장들을 컴파일 한다. 조건에 맞지 않으면 #if와 #endif 사이를 컴파일 하지 않고 넘어간다. #elif 조건 #if, #ifdef, #ifndef의 조건에 맞지 않을 경우 또 다른 조건을 검색하기 위한 지시어로 사용된다. #else 조건 #if, #ifdef, #ifndef의 조건에 맞지 않을 경우 #else와 #endif 사이의 문장들을 .. 2007. 3. 26.
C로 만든 숫자 야구 프로그램 #include #include #include int main() { int baseball[4]; int user[4]; int i, j, flag=1; int st, ball, out=0; srand(time(NULL)); baseball[0] = rand() % 10; while(baseball[0] == 0) // 처음값은 0이 들어가면 안된다. baseball[0] = rand() % 10; for(i=1; i 2007. 3. 24.
콘솔상에서 상자를 그려 위치 이동시키는 프로그램 #include #include #include #include #define ESC 27 #define UP 72 #define DOWN 80 #define LEFT 75 #define RIGHT 77 void textcolor(int i); void gotoxy(int x, int y); void box(int start_x, int start_y, int end_x, int end_y); void textcolor(int i) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), i); } void gotoxy(int x, int y) { COORD Pos = {x, y}; SetConsoleCursorPosition(GetStdHandle(STD.. 2007. 3. 23.
반응형