Actions

EmSys

C - Diagnostics2

From EdWiki

Revision as of 09:30, 23 June 2015 by Jshankar (Talk | contribs) (1 revision imported: EdWiki -- Emsys pages from Shukra)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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’ );
}