i'm thinking that a valid group ID name must start with an alphabetical character or an underscore..if this is true you can simply check the first character....
(impromptu code..not tested)
there is probably some error checking needed to be done here...but it depends on what you're going to use this data for and the exact specs of group ID's and numbers.
char token = NULL;
token = strtok(gidlist, ",");
if( isdigit(*token) )
id.nID = atoi(token);
id.lpszID = NULL;
//fake function below
id.nID = 0; // nID = lookUpLinuxGroupIdNumber(token)
printf("Group Name: %s; Group ID: %d\n", id.lpszID, id.nID);
token = strtok(NULL, ",");
by the way...use code tags when posting code