how to stop text color function under conio.h in C to align the output to right??is there any way to reset text attributes to normal in C

StackOverflow https://stackoverflow.com/questions/12821005

문제

int main()
{
    int i ;
    clrscr();
    for(i = 0; i <= 6; i++) {
        if(i % 2 == 0) {
            **textcolor(2);**
            cprintf("%d\n", i);
        }

        if(i % 2 != 0) {
            **textcolor(3);**
            cprintf("%d\n", i);
        }
    }
    getch();
}

OUTPUT:(all evens are in green and odds in blue)

0

 1

  2

   3

    4

      5

        6
도움이 되었습니까?

해결책

Probably \n is used literally and only does a line feed (= jump to next line and keep cursor at same column) and no carriage return (= put cursor at start of line). Change the \ns inside the calls to cprintf to \r\n.

다른 팁

Newlines in Windows is "\r\n". Apparently the cprintf doesn't translate '\n' into the correct sequence so all you are doing is going to the next line with the line feed but you do not put the "cursor" at the beginning if the line with '\r' (carriage return).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top