0

/It is not taking name as input.Skipping name and moving on to branch./

        void input()
        {
            char s[1000];
            fflush(stdin);
            cout<<"Enter the name : ";
            cin.getline(s,sizeof(s));
            name=new char[strlen(s)+1];
            strcpy(name,s);
            fflush(stdin);
            cout<<"Enter the branch  : ";
            cin.getline(s,sizeof(s));
            branch=new char[strlen(s)+1];
            strcpy(branch,s);
            fflush(stdin);
            cout<<"Enter the roll number : ";
            cin>>rollno;
            fflush(stdin);

        }

/*Code Snippet for taking input of of object array s[i] of class student of which the above method void input() is part of */

    for(i=0;i<n;i++)
    {
        cout<<endl;
        s[i].input();
        for(j=0;j<m;j++)
        {
            cout<<endl;
            cout<<"For ";
            sb[j].out();
            cout<<" : "<<endl;
            sb[j].input();
        }
    }
  • The dupe isn't the exact same function, but it's the same problem. You leave a newline behind when you enter the roll number. By the way, `fflush(stdin)` is explicitly called out as undefined behaviour. I'd advise not doing that. – chris Jun 08 '19 at 08:38
  • so what should be used instead of fflush(stdin) @chris – Anshul Somvanshi Jun 08 '19 at 09:36
  • The linked question uses `ignore` to discard input. – chris Jun 08 '19 at 09:44

0 Answers0