Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
/* The aim of the program is to split the contents in e[i] and add them to the arrays name , surname and score. */

int main()
{
    int entry,i,option;
    printf("\nPlease indicate the number of records you want to enter :\n");
    scanf("%d",&entry);
    char ent[entry][100],name[entry][20],surname[entry][20],score[entry][10];
    printf("\nPlease input records of students (enter a new line after each record), with following format first name last name score \n");

    for (i=0; i<entry+1; i++)
    {
        gets(ent[i]);
        printf("%s",ent[i]);
    }

    for(i=0; i<entry+1; i++)
    {
        name[i] = strtok(ent[i]," ");   <- Error
        printf("\n%s\n",name[i]);
    }

    printf("\nPlease choose the appropriate options :");
    printf("\nPrint records (press 1)\nSearch by first name (press 2)\nSearch by last name (press 3)\nSort by score (press 4)\nSort by last name (press 5)\nExit the program (press 0)\n");
    scanf("%d",&option);
    return 0;
}
Posted
Updated 30-Mar-15 20:20pm
v4
Comments
George Jonsson 31-Mar-15 2:22am    
try strncpy(name[i], strtok(ent[i]," "), sizeof(name[i]));
[no name] 31-Mar-15 2:42am    
strncpy or strcpy ?
George Jonsson 31-Mar-15 2:48am    
strncpy is safer than strcpy. You pick a winner.

1 solution

C#
//Your for loops appear to be incorrect
//Arrays are zero based, so the range is 0 to entry-1 

    for (i=0; i<entry;>    {
        gets(ent[i]);
        printf("%s",ent[i]);
    }
 
    for(i=0; i<entry;>    {
        name[i] = strtok(ent[i]," ");  
        printf("\n%s\n",name[i]);
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900