Actions

EmSys

C - Diagnostics2

From EdWiki

Diagnostics:

What is wrong with the following code ??

// getline --- read a \n delimited line into a buffer
void getline(char* pch)
{
    int ch;
    do {
 	assert( (ch = getchar() != EOF );
    }while( (*pch++ = ch) != ‘\n’ );
}

Proper coding

// getline --- read a \n delimited line into a buffer
void getline(char* pch)
{
    int ch;
 
    do {
        ch = getchar();
	assert( ch != EOF );
    }while( (*pch++ = ch) != ‘\n’ );
}