0

Problem in making 3 member of structure of 3 student info

I tried to make a structure of 3 member ( int roll_no,float percentage,char name[20]) but my program did not taking input and i also used fflush but it not working please help #include <stdio.h> struct student { char name[50]; int roll; float per; } s[3]; void main() { int i; for(i=0;i<=2;i++){ printf("Enter information:\n"); printf("Enter name: \n"); gets(s[i]].name); printf("Enter roll number:\n "); scanf("%d", &s[i]].roll); printf("Enter percentage:\n "); scanf("%f", &s[i]].per);} printf("Student info"); for(i=0;i<=2;i++){ printf("Student name %s \n",s[i].name); printf("Roll no %d",s[i].roll); printf("Percentage %f",s[i].per);} }

14th Jul 2020, 12:11 PM
Harsh Kumar Sharma
12 Réponses
+ 2
I also faced this problem. fflush is not works on sl. So you use cin.ignore() before cin. https://www.sololearn.com/discuss/2375153/?ref=app more about input buffers: https://www.google.co.in/amp/s/www.geeksforgeeks.org/clearing-the-input-buffer-in-cc/amp/
14th Jul 2020, 12:48 PM
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ - avatar
0
#include <stdio.h> struct student { char name[50]; int roll; float per; } s[3]; void main() { int i; for(i=0;i<=2;i++){ printf("Enter information:\n"); printf("Enter name: \n");fflush(stdin); gets(s[i]].name); printf("Enter roll number:\n "); scanf("%d", &s[i]].roll); printf("Enter percentage:\n "); scanf("%f", &s[i]].per);} printf("Student info"); for(i=0;i<=2;i++){ printf("Student name %s \n",s[i].name); printf("Roll no %d",s[i].roll); printf("Percentage %f",s[i].per);} } Please gyz ye program work nhi kr rha help me
14th Jul 2020, 1:06 PM
Harsh Kumar Sharma
0
https://code.sololearn.com/c71AyFP65kK0/?ref=app Now its working or not??? please tell me because it not taking input
14th Jul 2020, 2:24 PM
Harsh Kumar Sharma
0
https://code.sololearn.com/c71AyFP65kK0/?ref=app Bro its not working i insert getchar(); but it will not input any value by user but showing direct output
14th Jul 2020, 3:13 PM
Harsh Kumar Sharma
0
https://code.sololearn.com/c71AyFP65kK0/?ref=app Bro can i use this same program in turbo C and will it work fine???
14th Jul 2020, 3:34 PM
Harsh Kumar Sharma
0
Bro its not working on other compiler when i click on run it runs but take only name and when i type roll no its came out on program screen help me
15th Jul 2020, 10:20 AM
Harsh Kumar Sharma