Skip to main content
added 22 characters in body
Source Link

I have a problem that when the users type same id,they need to type name and id again. How can i only ask the users to input the id rather than both name and id,when the users type same id number.Please give me some hints how to do that.Thanks for your help!

struct student
{
    intchar student_num;student_name[30];          
    char student_name[50];student_id[10];            
    int student_id[30];student_course_num[20]; 
    int student_course[10];
}; 

int main()
{
    struct student S;
    int i,j,student_code=1;student_num;

printf("Enter the number of studentstudents:");
scanf("%d",&S.student_num&student_num);
int StuNum=S.student_num;

forfflush(i=0;i<StuNum;i++stdin)
{;
   struct printf("Numberstudent ofS[student_num];
char StudentsTestForId[student_num][10];
int %d:\n"i,student_codej,student_code=1;
for(i=0;i<student_num;i++);
{
    printf("Enter the name of student:");
    scanffgets("%s",&SS[i].student_name[i]student_name,30,stdin);
    fflush(stdin);
    printf("Enter the Student ID (8 digits):");
    scanffgets("%d",&SS[i].student_id[i]student_id,10,stdin);
    fflush
    strcpy(stdinTestForId[i],S[i].student_id);
    for(j=0;j<i;j++)
    {
        if(S.student_id[j]==Sstrcmp(TestForId[j],S[i].student_id[i]student_id)  //whether the id is same or not==0)
        {
            printf("<ID NUMBER HAS ALREADY EXITED>\n");
            i--;
       "The student id has already student_code--exit\n");
            break;
        }
    }
    student_code++; 
}   

}

I have a problem that when the users type same id,they need to type name and id again. How can i only ask the users to input the id rather than both name and id,when the users type same id number.Please give me some hints how to do that.Thanks for your help!

struct student
{
    int student_num;
    char student_name[50];      
    int student_id[30];
    
};
int main()
{
    struct student S;
    int i,j,student_code=1;

printf("Enter the number of student:");
scanf("%d",&S.student_num);
int StuNum=S.student_num;

for(i=0;i<StuNum;i++)
{
    printf("Number of Students %d:\n",student_code);
    printf("Enter the name of student:");
    scanf("%s",&S.student_name[i]);
    fflush(stdin);
    printf("Enter the Student ID :");
    scanf("%d",&S.student_id[i]);
    fflush(stdin);
    for(j=0;j<i;j++)
    {
        if(S.student_id[j]==S.student_id[i])  //whether the id is same or not
        {
            printf("<ID NUMBER HAS ALREADY EXITED>\n");
            i--;
            student_code--;
            break;
        }
    }
    student_code++; 
}   

}

I have a problem that when the users type same id,they need to type name and id again. How can i only ask the users to input the id rather than both name and id,when the users type same id number.Please give me some hints how to do that.Thanks for your help!

struct student
{
    char student_name[30];          
    char student_id[10];            
    int student_course_num[20]; 
    int student_course[10];
}; 

int main()
{
int student_num;

printf("Enter the number of students:");
scanf("%d",&student_num);
fflush(stdin);
struct student S[student_num];
char TestForId[student_num][10];
int i,j,student_code=1;
for(i=0;i<student_num;i++)
{
    printf("Enter the name of student:");
    fgets(S[i].student_name,30,stdin);
    
    printf("Enter the Student ID (8 digits):");
    fgets(S[i].student_id,10,stdin);
    
    strcpy(TestForId[i],S[i].student_id);
    for(j=0;j<i;j++)
    {
    if(strcmp(TestForId[j],S[i].student_id)==0)
    {
        printf("The student id has already exit\n");
    }
    }
    student_code++;
}   
Source Link

How to print specific data in c?

I have a problem that when the users type same id,they need to type name and id again. How can i only ask the users to input the id rather than both name and id,when the users type same id number.Please give me some hints how to do that.Thanks for your help!

struct student
{
    int student_num;
    char student_name[50];      
    int student_id[30];
    
};
int main()
{
    struct student S;
    int i,j,student_code=1;

printf("Enter the number of student:");
scanf("%d",&S.student_num);
int StuNum=S.student_num;

for(i=0;i<StuNum;i++)
{
    printf("Number of Students %d:\n",student_code);
    printf("Enter the name of student:");
    scanf("%s",&S.student_name[i]);
    fflush(stdin);
    printf("Enter the Student ID :");
    scanf("%d",&S.student_id[i]);
    fflush(stdin);
    for(j=0;j<i;j++)
    {
        if(S.student_id[j]==S.student_id[i])  //whether the id is same or not
        {
            printf("<ID NUMBER HAS ALREADY EXITED>\n");
            i--;
            student_code--;
            break;
        }
    }
    student_code++; 
}   

}