Is this code valid under g++

Ajay Bansal Ajay_Bansal@infosys.com
Thu Mar 20 18:39:00 GMT 2003


Is the following code corect??


char*
getNextItem(char* line, const char* delimit)
{
    // Retrieve the next item, and strip off any whitespace around it
    char* item;
    char* tmp;

    item = strtok(line, delimit);
    if (item)
    {
        // Strip off leading whitespace
        while (*item == ' ' || *item == '   ')
        {
            item++;
        } // while

        // Find any trailing spaces, tabs, newlines
        tmp = strpbrk(item, " \t\n");
        if (tmp)
        {

            *tmp = '\0';
        } // if

        // Comment, or end of line
        if (*item == '#' || *item == '\n' || *item == '\0')
        {
            // Return as if nothing
            item = 0;
        } // if
    } // if

    return item;
} // getNextItem()


CAN WE RETURN item (it is local to the function)



More information about the Gcc-help mailing list