경고 눈이 썩을 수 있습니다





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// index와 key보드 값을 넣으면 tempEnterables에 따라 증가하거나 감소한 focus(배열의index)가 반환된다.
// RIGHT : x증가        LEFT : x 감소 (index ++ or -- )
// UP     : y증가        DOWN : y 감소 (index = y가 바뀌는 index)
int changeVertexFocus( int arrowKeyConst, int focus, IntStack* tempEnterables )
{
    Vertex** vertexArr = (Vertex**)( &tempEnterables->arr[1] );    
    int maxIndex = tempEnterables->top - 1;// 새 배열 vertexArr의 최대 인덱스이다.
    Crossing* prevCrossing = NULL;
    Crossing* nowCrossing = NULL;
 
    if( focus < 0 ){
        printf"fatal error. changerVertexFocus의 focus인수( == %d )대입이 잘못되었습니다.", focus);
        //exit(1);
    }
 
    switch( arrowKeyConst ){
 
        case RIGHT:
            if( focus == maxIndex ){
                focus = 0;
            }else{
                focus++;
            }
            break;
        
        case LEFT:
            if( focus == 0 ){
                focus = maxIndex;
            }else{
                focus--;
            }
            break;
            
        case UP:
            do{
                if( focus == 0 ){
                    focus = maxIndex;
                    break;
                }else{
                    prevCrossing = (Crossing*)vertexArr[focus]->data;
                    nowCrossing = (Crossing*)vertexArr[focus-1]->data;
                    focus--;
                }
            }while(prevCrossing->point.y == nowCrossing->point.y);
                
            break;
 
        case DOWN:
            do{
                if( focus == maxIndex ){
                    focus = 0;
                    break;
                }else{
                    prevCrossing = (Crossing*)vertexArr[focus]->data;
                    nowCrossing = (Crossing*)vertexArr[focus+1]->data;
                    focus++;
                }
            }while(prevCrossing->point.y == nowCrossing->point.y);
                
            break;
            
        default:
            puts("changeVertexFocus함수 호출이 잘못되었다");
            //exit(1);
            break;
    }
    
    return focus;
    
}
 
 
cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// thanks to codesafer.
// 확실히 좋은 방법이다. 나중에 이걸 할 일이 있다면 이용해보자...
void getn(int* n )
{
    int ch;
    
    *= 0;
 
       while(1){
        ch = getchar(); 
        
        if( ch >= '0'  &&  ch <= '9' ){//숫자가 나올 때까지 돌린다.
            
            do{
                *= ** 10 + (ch - '0'); //아스키코드를 숫자로 바꾸고 자릿수까지 맞춰준다
                ch = getchar(); 
            }while(ch >= '0'  &&  ch <= '9');
            
            return;
        }
        else{
            *= -1;
            return;
        }
    }
}
 
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 
//char포인터 fptr를 연속된 수의 자릿수만큼 옮기면서 수를 int형으로 반환
//fptr에 파일 포인터를 넣어 사용.
// 1234\t  에서 fptr = &'1'으로 함수를 쓰면 fptr는 함수 반환 후엔 '\t'를 가리키게 된다.
int readNumAndMoveFilePtr(char** fptr)// 양수만 가능.
{
    int digit, result = 0;
    int i, count = 0, returnValue = 0;
 
    digit = 1;
    do{
        result += digit * charToInt(**fptr);
        digit *= 10;
        *fptr += 1;
        count++;
    }while**fptr != '\t' && **fptr != '\n' );
    
    digit /= 10;    // digit의 자릿수는 result의 자릿수*10이다.
    for(i = 1; i <= count; i++){
        returnValue += (result % 10* digit;
        result /= 10;
        digit /= 10;
    }
    return returnValue;
}
 
cs



음... 3번 썼네