This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Is this code valid under g++


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)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]