Start New Discussion within our Software Development Community

Anyone please help me to find out ...where is the error because this program will continue untill the user enter 0 the program will terminate ...but i stuck at here please help...

#include<stdio.h>

struct student{
int id_no;
char name;
int average;

int main()
{
struct student stud1;

do{

printf("Enter Index No : ");
scanf("%d",&stud1.id_no);
printf("Enter name : ");
scanf("%s",&stud1.name);
printf("Enter average : ");
scanf("%d",&stud1.average);

printf("\n");

}while(stud1.id_no!=0);

return 0;
}
#include<stdio.h>

struct student
{
   int id_no;
   char name;
   int average;
};

int main()
{
    struct student stud1;

    do
    {
       printf("Enter Index No : ");
       scanf("%d",&stud1.id_no);
       printf("Enter name : ");
       scanf("%s",&stud1.name);
       printf("Enter average : ");
       scanf("%d",&stud1.average);

       printf("\n");

    } while( stud1.id_no != 0 );

    return 0;
}

Where is your indentation my friend. This time I've done it for you. But don't ever expect that next time. Otherwise you wont expect any help from here. I am afraid.

Back the problem, well the program had been designed to get as many details from the user until the user enters 0 for student_id.

} while( stud1.id_no != 0 );

So what are you trying to achieve. If you could give us more information. we might be able to give some solutions and ideas. And the above snap of code is the one which you should be looking at. The reason it goes on forever asking details is because the the scanf statment are kept inside the do-while loop. Until the loop condition break you will asked for student details. If you just need to get one student details, then perhaps you should remove all those printf's and scanf's function out from the do-while loop and take off those loops completely from there.

ssharish

This article has been dead for over six months. Start a new discussion instead.