Click here to Skip to main content
14,735,834 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
#include<stdio.h>
#include<string.h>
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++)
    {
        printf("%d",i);
        gets(ent[i]);
        printf("%s",ent[i]);
    }

    for(i=0;i<entry-1;i++)
    {
        strncpy(name[i],strtok(ent[i]," "),sizeof(name[i]));
        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 22:27pm
v2
Comments
George Jonsson 31-Mar-15 3:31am
   
It basically can't.
Are you sure you don't execute both printf("%d",i); and printf("%s",ent[i]);?
Try add a \n in the first print.
printf("%d\n",i);

1 solution

Basically because gets gets (pardon the pun) scanf unconsummated buffer. You may easily see that changing from
Quote:
printf("%d",i);
gets(ent[i]);
printf("%s",ent[i]);

to
printf("%d\n",i);
gets(ent[i]);
printf("[%s]\n",ent[i]);
   

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