Actions

EmSys

Difference between revisions of "CCoding Style - Use else-ifs for multi-way decisions3"

From EdWiki

m (1 revision)
 
m (1 revision imported: EdWiki -- Emsys pages from Shukra)
 
(No difference)

Latest revision as of 09:30, 23 June 2015

Use else-ifs for multi-way decisions ...

    If( argc != 3 )
        printf( “Usage : cp inputfile outputfile\n” );
    else if( ( fin = fopen( argv[1], “r”) ) == NULL )
        printf( “Can’t open input file %s\n”, argv[1] );
    else if( ( fout = fopen( argv[2], “w”) ) == NULL ) {
        printf( “Can’t open output file %s\n”, argv[2] );
        fclose(fin);
    } else {
        while( ( c = getc(fin) ) != EOF )
            putc(c, fout);
        fclose(fin);
	fclose(fout);
    }