- 4

Copy-Paste & Run this code & please inform me what is wrong here....

#include<stdio.h> struct student { char name[30]; int ID; char dp[50]; int phone; } student1, student2; int main() { printf("Enter your Full Name: "); fgets(student1.name,sizeof(student1.name),stdin); printf("Insert your ID no: "); fgets(student1.dp,sizeof(student1.dp),stdin); printf("Enter your department name: "); scanf("%s", &student1.dp); printf("Enter your mobile number: "); scanf("%d", &student1.phone); printf("\n\n"); printf("Enter your Full Name: "); fgets(student2.name,sizeof(student2.name),stdin); printf("Insert your ID no: "); scanf("%d", &student1.ID); printf("Enter your department name: "); fgets(student2.dp,sizeof(student2.dp),stdin); printf("Enter your mobile number: "); scanf("%d", &student2.phone);

8th Apr 2022, 1:30 PM
Adnan Faisal
7 odpowiedzi
+ 4
Code is truncated..!! Why don't you share code link by saving it in playground? edit: you are taking dp values twice.. may you overlaping inputs......
8th Apr 2022, 1:37 PM
Jayakrishna 🇮🇳
+ 3
Did you see what errors will be show from a debugger and tried to eliminate?
8th Apr 2022, 2:20 PM
JaScript
JaScript - avatar
0
it's showing no error- but when i insert input in ID,, it automatically jump to phone statement, without taking input of dp statement.... dp gets skipped all the time, but why?🤔
8th Apr 2022, 4:48 PM
Adnan Faisal
0
As I told above, You are using student.dp twice to taking into for student1.. So it's skips by taking space only.. I think.. To better understand, full code is required there...
8th Apr 2022, 4:54 PM
Jayakrishna 🇮🇳
0
Also mention what inputs you are giving in what way.. is also may matters...
8th Apr 2022, 4:56 PM
Jayakrishna 🇮🇳
0
Can you explain me a little more? Where i'm using dp twice?
8th Apr 2022, 4:57 PM
Adnan Faisal
0
See these lines : printf("Insert your ID no: "); fgets(student1.dp,sizeof(student1.dp),stdin); printf("Enter your department name: "); scanf("%s", &student1.dp); Instead of accepting int value for ID, you are taking dp twice by fgets and scanf.. Where are you taking input to ID?
8th Apr 2022, 6:51 PM
Jayakrishna 🇮🇳