C Language Travel Agency Manager Exercise 7 Solution: C Tutorial In Hindi #46
HTML-код
- Опубликовано: 5 окт 2024
- In this series of C programming in hindi tutorial videos, I have explained you everything you need to know about C language. I hope you are enjoying this C in Hindi course.
►This C Lecture is a part of this C Programming Course: • C Language Tutorials I...
►Source Code + Notes: codewithharry....
►Click here to subscribe - / @codewithharry
Best Hindi Videos For Learning Programming:
►Learn Python In One Video - • Learn Python In Hindi ...
►Learn JavaScript in One Video - • JavaScript Tutorial
►Learn PHP In One Video - • Learn Php In One Video...
►Machine Learning Using Python - • Machine Learning Tutor...
►Creating & Hosting A Website (Tech Blog) Using Python - • [Hindi] Web Developmen...
►Advanced Python Tutorials - • Intermediate/Advanced ...
►Object Oriented Programming In Python - • Object Oriented Progra...
►Python Data Science and Big Data Tutorials - • Python Data Science an...
Follow Me On Social Media
►Website (created using Flask) - www.codewithha...
►Facebook - / codewithharry
►Instagram - / codewithharry
►Personal Facebook A/c - / geekyharis
Twitter - / haris_is_here
For future Viewers :
1. in this program, Scanf will not take whitespace , so use fgets
2. However, you will have to use scanf for integer input, which when combined with fgets, will not allow you to take string input for the next fgets, as scanf generates newline charecter(
) which gets consumed by fgets and hence you'll not be able to take input
3. To solve this , write getchar(); function after each scanf so that it consumes the newline charecter , thus allowing you to take input .
i wrote using gets, posted the code as a reply to ur comment, can u post ur code with fgets plz
@@clubsign36
See
#include
#include
typedef struct drivers
{
char name[20];
char license[30];
char route[20];
float kms
}d;
int main()
{ int n,len;
printf("Enter number of drivers :");
scanf("%d",&n);
getchar();
d drivers[n];
for(int i =0;i
Thank you sir. You had made it easier by keeping the number of drivers to three. But I wanted to make it hard for myself so that I learn more, so I made the program for n number of drivers and I was successful in making the program in less than 50 lines. Yes, I used for loop twice, once for taking input and once for printing output. Thank you sir 🙏❤️
can u please show me the code
@@shreyadasmahapatra5332 give me your email id so that I can send the c file to you
@@stubborn1861
I have used this code for solving it by loop method . If you found this useful please like this so that others can see it . I spent a lot of time on this.
I have used array as structure variable and passed it as argument to the function display.
But we can't decide the length of array s beforehand so I took it = 10( long enough)
#include
#include
struct data
{
int km;
int dlno;
char name[30];
char route[20];
}s[10];
display(struct data s[],int n)
{
for(int i=1;i
@@stubborn1861 he probably declared the structure variable as an array
Struct d
{
definition
} dn[] ;
Same here
Hey which job do you do as you are an excellent teacher do you work like a software engineer also
Sir you are a motivation for us doing great job!! keep going
thank you harry bhai
Harry bhai please make a video on Data Structures.....
harry bhai you could use loop for detail entering as if there were many than what to do i tried and got the desired outcome and i used array for structre
I also used the array of structure to solve this problem
I like your video so much 🙏🙏
loved your course☺☺
Bestcoder in you tube
Great tech
Really a great explanation Harry Bhai
Because of ur explaination I have started programming in c
Keep going on bro you are doing an great job🙂
Thank you for yout course
Thank you for your guidance
Bro mana bhi aasa hi likha tha but Mera first input lakr sabhi nicha k print kr rha hai. Or aaga wala scanf bhi ignore kr rha hai.
Are Bhai Bhai bhai Bhai Naya exercise a gaya
Vai genetic algorithm pe video banaiye please ☺
Bewt bro got it easily
I have used loops here
#include
#include
struct driver
{
char name[50];
char licence_no[5];
char route[50];
int kms;
}data[2];
int main()
{
int i,n;
printf("Enter Number Of drivers: ");
scanf("%d",&n);
for(i=0;i
can you please explain why data [2] ?
data[n] hoga na just declare it after asking for n
@@ankushghosh1799 he took data[2] as an array , means only 2 driver details can be entered. he should have took data[n] after taking value of n by the user
@@Rounakrk thanks brother
thank you
Sir, in this program I add money in the struct and run this program by for loop. Run successfully. But I want to add the total money earned in a day by the travel agency, I failed. Apart from this, I used in this program Goto statement, how will it work? Because goto statement isn't working. Please help.
very
nice
You have deep knowledge of the programming
you should use loop here for many inputs that make the code small
#include
#include
struct drivers
{
char name[50];
char licNum[50];
char route[50];
char KMs[50];
} driver;
int main()
{
while (1)
{
printf("1 enter your name:
");
printf("2 enter your license number:
");
printf("3 enter your route:
");
printf("4 enter your kms:
");
gets(driver.name);
gets(driver.licNum);
gets(driver.route);
gets(driver.KMs);
printf("your Name is:%s
", driver.name);
printf("your licNum is:%s
", driver.licNum);
printf("your route is:%s
", driver.route);
printf("your Kms is:%s
", driver.KMs);
}
return 0;
}
Bhai pehel ise chla k dekh bss ek hi person ka input lega ye or sirf likh while 1 pura program to bna le ..
Sir when i give spaces in between route name then it does not ask for printing my km.But when i dont give spaces between characters then it ask for printing kms
@kashu🐣 is there any alternative
like I tried using gets but It mess my code
what you said at the very first time in the the video that to take take the input from the user that how many drivers's info he want to print .....
please help me to write that code...
big follower sir ❤
I have used this code for solving it by loop method . If you found this useful please like this so that others can see it . I spent a lot of time on this.
I have used array as structure variable and passed it as argument to the function display.
But we can't decide the length of array s beforehand so I took it = 10( long enough).
#include
#include
struct data
{
int km;
int dlno;
char name[30];
char route[20];
}s[10];
display(struct data s[],int n)
{
for(int i=1;i
#include
#include
struct l {
char name[35];
int license;
char route[100];
int km;
};
int main() {
start:
int n;
printf("enter no of driver
");
scanf("%d",&n);
struct l m[n];
for (int i=0;i
Bhai isme for loop use karte to accha lagta 😊😊😊😊
Good Tutorial Love from Pakistan 💞
sir there is no source code in ur website for this video
there is a blank space in that box where source code must be prsent
Kms not printing integer but if i put zero it's run . How can i solve it?
Hairy bhoi ap blast ho😊😊
your question was different. It was to take input n from user but here you have predefined d1,d2,d3 and so on...
haan bro yahin krna tha toh isse hamaari coding skills kaise develop hui. Bas typing ki practice hui. Mujhe laga woh har data ke liye ek array banayenge aur phir array slicing se value print krdenge( like in python) but slicing isn't present in c language . So you can't print name of all drivers at once ( without manually taking input for all three).
I have used this code for solving it by loop method . If you found this useful please like this so that others can see it . I spent a lot of time on this.
I have used array as structure variable and passed it as argument to the function display.
But we can't decide the length of array s beforehand so I took it = 10( long enough).
#include
#include
struct data
{
int km;
int dlno;
char name[30];
char route[20];
}s[10];
display(struct data s[],int n)
{
for(int i=1;i
#include
#include
struct l {
char name[35];
int license;
char route[100];
int km;
};
int main() {
start:
int n;
printf("enter no of driver
");
scanf("%d",&n);
struct l m[n];
for (int i=0;i
bhaiya kuch challenging do na jo jyada dimag khaega
Harry bhai is hero.
Can we do it with loops?
#include
#include
int main()
{
int n;
struct driver
{
char name[50];
int license;
char route[50];
int kms;
} ta[20];
printf("------------Welcome sk tarvel agency--------------
");
printf("Enter the number of drivers details you want to fill:
");
scanf("%d",&n);
for (int i = 0; i < n; i++)
{
printf("
%d. Enter the driver name
",i+1);
scanf("%s", &ta[i].name);
printf("Enter the licence number:
");
scanf("%d", &ta[i].license);
printf("Enter the route:
");
scanf("%s", &ta[i].route);
printf("Enter the kilometres you drive:
");
scanf("%d", &ta[i].kms);
}
printf("----------Drivers Information---------------------
");
for (int i = 0; i < n; i++)
{
printf("
%d. Driver Name:%s
",i+1,ta[i].name);
printf("License Number=%d
", ta[i].license);
printf("Route=%s
", ta[i].route);
printf("kilometres=%d
", ta[i].kms);
}
return 0;
}
Sir, nahi he sorce code ess vale video me 😟😟😟
Harry bhia not satisfied with this solution😐
Pls tell here how we can reduse lines here with loop and one more thing gets() why not used here bcs scanf will terminate string name when driver enter their name with space
I tried many time but could't
Pls solve it with loop and gets function
bro if you know that how it can be improved then why are you asking him to solve it again................
@@nareshgoyal1994 bro this is really very long way of solving this
i tried using gets ,
but it is messing with my code 😞
@@yashrawat747
I have used this code for solving it by loop method . If you found this useful please like this so that others can see it . I spent a lot of time on this.
I have used array as structure variable and passed it as argument to the function display.
But we can't decide the length of array s beforehand so I took it = 10( long enough).
#include
#include
struct data
{
int km;
int dlno;
char name[30];
char route[20];
}s[10];
display(struct data s[],int n)
{
for(int i=1;i
Sir notes
How to use for loop in these
The %s format specifier in scanf expects a char* argument, which is the address of the first element of a character array. When we write d1.name, it already decays to char*, which is the correct type. Then how are you using &d1.name, which will be of type char** (pointer to pointer to character array)? Why do it not gives error? I have tried it without & (d1.name) and it works fine.
you're right.
can u see my code???
idk why but it is giving me some unpredictable behavior while taking inputs
#include
#include
struct info
{
char name[30];
int driving_license_id;
char route[30];
int Kms_travelled;
};
int main()
{
int n;
printf("The number of drivers is: ");
scanf("%d" , &n); // For the sake of simplicity , put n = 3;
struct info drivers[n];
struct info a;
printf("
Dear drivers, please give your infos:
");
for(int i = 0; i < n ; i++)
{
printf("Driver no.%d:
" , i+1);
printf("Name: ");
scanf("%s" , (a.name));
printf("Driving License ID: ");
scanf("%d", &(a.driving_license_id));
printf("Route: ");
scanf("%s" , (a.route));
printf("Kms travelled while recruited in the agency: ");
scanf("%d", &(a.Kms_travelled));
printf("
");
drivers[i] = a;
}
printf("
The drivers' info is thereby:
");
for(int i = 0 ; i < n ; i++)
{
a = drivers[i];
printf("Driver no.%d:
" , i+1);
printf("Name: %s
" , a.name);
printf("Driver's License ID: %d
" , a.driving_license_id);
printf("Route: %s
" , a.route);
printf("Kms travelled while recruited in the agency: %d
" , a.Kms_travelled);
printf("
");
}
return 0;
}
Bhai how to type fast ????
if n is unknown number then how to declare n variables in the structure?
#include
#include
typedef struct drivers
{
char name[20];
char license[30];
char route[20];
float kms
}d;
int main()
{ int n,len;
printf("Enter number of drivers :");
scanf("%d",&n);
getchar();
d drivers[n];
for(int i =0;i
Pta chal gya ho to muche bhi bta de bhai
bhai uskke liye apko ek structure ka array banana padega.uske bad appko ek for loop me users ka data entry karna padega.@@LavishKamboj01
/*
You manage a travel agency and you want your n drivers to input their following details:
1. Name
2. Driving License No
3. Route
4. Kms
Your program should be able to take n as input(or you can take n=3 for simplicity) and
your drivers will start inputting their details one by one.
Your program should print details of the drivers in a beautiful fashion.
User structures.
*/
#include
int main()
{
int num;
struct driver
{
char name[40];
char lis[40];
char route[40];
int kms;
};
printf("
\"**********Welcome to the Driving Agency**********\"
");
printf("Enter the number of diver's whose detail you want to store:
");
scanf("%d",&num);
getchar();
struct driver detail[num];
for (int i = 0; i < num; i++)
{
printf("Please provide the details of DRIVER NO %d:
", i + 1);
printf("Enter the name:");
gets(detail[i].name);
printf("Enter the License No:");
gets(detail[i].lis);
printf("Enter the Route:");
gets(detail[i].route);
printf("Enter the approx number of KMs Driven:");
scanf("%d", &detail[i].kms);
getchar();
printf("
");
}
printf("
**********The Details of drivers in our agency is:**********
");
for (int i = 0; i < num; i++)
{
printf("The name of Driver %d is :%s
", i + 1, detail[i].name);
printf("The License No is :%s
", detail[i].lis);
printf("The Route is :%s
", detail[i].route);
printf("The approx number of KMs Driven is :%d
", detail[i].kms);
printf("
");
}
printf("
");
return 0;
}
@@LavishKamboj01
Ok here n value is 3 so happily we have done it what if n value is 100 then it will become complicated so how to solve it easily
Jb selected portion m typing krte h tb intellisense work nhi krta. Uske lie 2 baar cursor ko neeche ya upar le jake wapis se shi jagah laake type krne se intellisense work krne lagta h
Bhaiya pointer to function ka video please 🥺
Sir, scanf aur gets ek saath kaam nehi kar raha hai
Brother you can use "fflush(stdin);" to clear buffer but use it before writing "gets" in your program.
Sir iss solutions k sir code nhi mil rehe sir plzz give....from Delhi
Harry bhai iss question ko loop se kaise solve kar sakte hai..??
Please btaiye...
How to do it using user input and looping?
can we solve this problem by using loops ??
yes we can use looping in this, I'm adding my Source code in this comment. I hope it will help you!!
@@anubhavkalra7216 thanks brother
@@anubhavkalra7216 please share me source code
@@anubhavkalra7216 plz share me source code for loop in structure
@@mandarbuchake2430 Brother I'd posted the source code in the above replies you can copy from there and If you can't find it then let me know.. I'll give you my code through mail.
sir vs code m bhot problems aati hai uski settings hi etni sari h ki hame kuch samajh nhi aata sir kya aap DEFAULT SETTINGS ki video bna sakte hai aur uske sath saare important extensions ki. idk why it is not compiling my code even tho its right i was ubuntu user
Bhai pygame tut plz
Pygame ke tutorial already sir ne bna ke rkha hai....
@@deepaktiwari-ry9yo heme aur game chaiye
@CodeWithHarry How to do the same program for 'n' drivers, taking 'n' as input from user?
Bro u can use concept of arrays in structures
like struct driver d[n];
and take n from user using scanf.
@@divyanshjindal18 like sir has taken d1 ,d2 ,d3
is there any way that we can take it from user like I tried in this way :
#include
#include
struct drivers
{
char name[50];
int distance ;
char route[50];
};
int main(int argc, char const *argv[])
{
// you have to take three drivers
char full_name[3][40];
for (int i = 1; i
can we use loop
#include
#include
struct drivers
{
char Name[30];
char Driving_Licence[30];
float KM;
} Driver_1, Driver_2, Driver_3;
int main()
{
printf(">
");
while (1)
{
for (int i = 1; i < 4; i++)
{
printf("\tEnter your identy according to the No.
Driver_%d
Name : ", i);
scanf("%s", &Driver_1.Name);
printf("Driving_licence : ");
scanf("%s", &Driver_1.Driving_Licence);
printf("KM : ");
scanf("%f", &Driver_1.KM);
printf("
");
printf("Driver_%d status
%s
%s
%f km
", i, Driver_1.Name, Driver_1.Driving_Licence, Driver_1.KM);
}
}
return 0;
}
I am 7th comment
Humbhi solve kiye hain
Can we use for loop ???
It will be less of code I guess
Yes you can. I can give you my source code if you give me your email id.
@@barunjena6171 thank you for the reply ☺️
I completed the entire series.
Now I am learning Java
@@divikas4495 wow, as soon as I complete this course, I will be learning python😀👍
@@barunjena6171 before learning python learn Data structures and algorithms
@@divikas4495 okay, thanks for the tip. I will look into it.
Bhai mera program run hi nahi kiya aapne
why you cant use for loop?
harry how will i assign no. of driver taken by user input lets say 10 then how will i initialize structure with 10 ,please tell
#include
#include
struct l {
char name[35];
int license;
char route[100];
int km;
};
int main() {
start:
int n;
printf("enter no of driver
");
scanf("%d",&n);
struct l m[n];
for (int i=0;i
Sir mere laptop me vs code nhii chal rha hai
Jab antivirus off kar rha hu tab chal rha hai
Abb Mai kya kru ?
Sir please reply
Can someone pls tell how can this be done using for loop?
I have used this code for solving it by loop method . If you found this useful please like this so that others can see it . I spent a lot of time on this.
I have used array as structure variable and passed it as argument to the function display.
But we can't decide the length of array s beforehand so I took it = 10( long enough).
#include
#include
struct data
{
int km;
int dlno;
char name[30];
char route[20];
}s[10];
display(struct data s[],int n)
{
for(int i=1;i
#include
/*you manage a travel agency and you want your n drivers to input their
following details:*
1 . Name
2. Driving License No.
3. Route
4. Kms*/
struct deriverdetails{
char Name[34];
int LicenseNo;
char Route[50];
int kms;
}s[5];
int main(){
int n,i;
printf("Enter the number of drivers to fill the details :
");
scanf("%d",&n);
for(i=1;i
#include
#include
struct l {
char name[35];
int license;
char route[100];
int km;
};
int main() {
start:
int n;
printf("enter no of driver
");
scanf("%d",&n);
struct l m[n];
for (int i=0;i
there is no code provided in the source code link plz check brother.
There is no print show after the line **priinting the details of the driver**
In my code.।। Can anyone help
I will hire you I am the CEO of various company like marcer
😂😂
First viewer
********* The source code is blank. **********
Sir, while using the gets() and puts() function in it, why the program not worked properly.
I'm stuck with this question.
it would not same problem here its compiler error use gets char() for correct output here my soution
#include
#include
struct l {
char name[35];
int license;
char route[100];
int km;
};
int main() {
start:
int n;
printf("enter no of driver
");
scanf("%d",&n);
struct l m[n];
for (int i=0;i
I did solve the same way.
I thought there must be another method cause this one is very lengthy method!!!
you can use for loop and functions
i tried to do it
it took me whole freaking 10 days to automate but 😞 sir did it in very common way
@@parthjoshi5939 i though of how many drivers from users and wanted to take input from user and put it in front of struct
but I fail very badly ,
How to make it for n numbers of drivers ?
Please reply
Make an array of structures, take n as an input (say n) and then write:
Struct name_of_structure Array_name[n];
bro why didnt use array instead than typing all of this much ??
How replicat the code sentence
Sir please solve this problem by loop 🙏.
Bro i solved it using loop, i was expecting harry bhai to do the same but idk why he did it that way.
#include
/*
You manage a travel agency and you want your n drivers to input their following details:
1. Name
2. Driving License No
3. Route
4. Kms
Your program should be able to take n as input(or you can take n=3 for simplicity) and your drivers will start inputting their details one by one.
Your program should print details of the drivers in a beautiful fashion.
User structures.
*/
struct details{
char name[20][20], licenseNum[20][20], route[20][20];
int kms[];
};
int main()
{
int n;
char companyName[20][20];
struct details d1, d2, d3,d4,d5;
printf("Enter the name of your company:
");
scanf("%[^
]", &companyName);
printf("Enter the number of drivers working under you:
");
scanf("%d", &n);
printf("Enter the details below:
");
for (int i = 0; i < n; i++)
{
printf("Input Details of Driver %d
Name of the driver: ", i+1);
scanf("%s", &d2.name[i]);
printf("License number of the driver: ");
scanf("%s", &d3.licenseNum[i]);
printf("Route taken by the driver: ");
scanf("%s", &d4.route[i]);
printf("Number of KiloMetres driven under service: ");
scanf("%d", &d5.kms[i]);
}
printf("The Details of The Drivers Working Under %s are:
", companyName);
for (int j = 0; j < n; j++)
{
printf("Name: \t%s
", d2.name[j]);
printf("License Number: \t%s
",d3.licenseNum[j]);
printf("Route: \t%s
", d4.route[j]);
printf("KiloMetres Driven: \t%d
", d5.kms[j]);
}
}
@@VarunG-y6p us moment 🫂.
Soaib aslam
For loop se kya
First
yaar apne to bola the ki n number of drivers and wo n user dalega issiliye bohot confusion hogaya
anybody who has solved this question with the help of loops. pls let me know. i am finding the loop method for this question
make array of structures D[3]; and then use it in loop. For ex. for loop in i:&D[i].name etc.
@नाक
I have used this code for solving it by loop method . If you found this useful please like this so that others can see it . I spent a lot of time on this.
I have used array as structure variable and passed it as argument to the function display.
But we can't decide the length of array s beforehand so I took it = 10( long enough).
#include
#include
struct data
{
int km;
int dlno;
char name[30];
char route[20];
}s[10];
display(struct data s[],int n)
{
for(int i=1;i
Loop ka use kark program chota kaise kare
Aise:
#include
/*
You manage a travel agency and you want your n drivers to input their following details:
1. Name
2. Driving License No
3. Route
4. Kms
Your program should be able to take n as input(or you can take n=3 for simplicity) and your drivers will start inputting their details one by one.
Your program should print details of the drivers in a beautiful fashion.
User structures.
*/
struct details{
char name[20][20], licenseNum[20][20], route[20][20];
int kms[];
};
int main()
{
int n;
char companyName[20][20];
struct details d1, d2, d3,d4,d5;
printf("Enter the name of your company:
");
scanf("%[^
]", &companyName);
printf("Enter the number of drivers working under you:
");
scanf("%d", &n);
printf("Enter the details below:
");
for (int i = 0; i < n; i++)
{
printf("Input Details of Driver %d
Name of the driver: ", i+1);
scanf("%s", &d2.name[i]);
printf("License number of the driver: ");
scanf("%s", &d3.licenseNum[i]);
printf("Route taken by the driver: ");
scanf("%s", &d4.route[i]);
printf("Number of KiloMetres driven under service: ");
scanf("%d", &d5.kms[i]);
}
printf("The Details of The Drivers Working Under %s are:
", companyName);
for (int j = 0; j < n; j++)
{
printf("Name: \t%s
", d2.name[j]);
printf("License Number: \t%s
",d3.licenseNum[j]);
printf("Route: \t%s
", d4.route[j]);
printf("KiloMetres Driven: \t%d
", d5.kms[j]);
}
}
sir i'm Deepak from firozaabd up 283203
aapka computer slow nahi. mere sath bhi yahi hota hai.C program itna slow kyu hota hai
?
Harry please start your coaching classes i am ready to join where u say. At any place.
By the way where u from.
Thank you for this knowledge.
And please reply.
Pata hai bade log ho par reply jurur dena
😂🔔
How %s is working with ampersand(&)?
Scanf() only works with ampersand "&"
no for string as far as i know there is no need for & while taking string input with the help of scanf 🙂
Please Give New Project
08-06-24
why didn't we used "gets()" to take the input of string
Only for simplicity bro
@नाक first i m getting warnign
and also my code isn't working properly with gets
Meri intellisence to ati hi ni hai😂😂😂
😂😂
🤣🤣🤣🤣🤣🤣🤣🤣🤣🤣🤣🤣🤣🤣🤣🤣
bhai visual c++ error in python
source code was disappear
Accept challenge
mera loops se nahi ho rha
#include
#include
struct l {
char name[35];
int license;
char route[100];
int km;
};
int main() {
start:
int n;
printf("enter no of driver
");
scanf("%d",&n);
struct l m[n];
for (int i=0;i
@@vatsalsharma4061 Thanks bro, I had already solved my problem.
Agr main name k beech me space de deta hu to wo next step me DL no. nhi poch rha seedhe route pr chala jaa rha.
How to solve this?
Pls tell
my name is Himanshu Shah
#include
#include
struct driverin
{
char name[30];
int dl;
float kms;
};
void main()
{
struct driverin d1,d2,d3;
int n;
printf("Enter 1 to give deteils for driver 1,
2 to give details for driver 2,
3 to give details for driver 3
");
scanf("%d", &n);
switch (n)
{
case 1:
{
printf("give your name to print
");
scanf("%s", &d1.name);
printf("give& your dl to print
");
scanf("%d", &d1.dl);
printf("give how much distance you have visited with the car to print
");
scanf("%f", &d1.kms);
printf("So the driver name is %s
,His dl number is %d
,He visted %f kms with the car
", d1.name, d1.dl, d1.kms);
break;
}
case 2:
{
printf("give your name to print
");
scanf("%s", &d2.name);
printf("give your dl to print
");
scanf("%d", &d2.dl);
printf("give how much distance you have visited with the car to print
");
scanf("%f", &d2.kms);
printf("So the driver name is %s
,His dl number is %d
,He visted %f kms with the car
", d2.name, d2.dl, d2.kms);
break;
}
case 3:
{
printf("give your name to print
");
scanf("%s", &d3.name);
printf("give your dl to print
");
scanf("%d", &d3.dl);
printf("give how much distance you have visited with the car to print
");
scanf("%f", &d3.kms);
printf("So the driver name is %s
,His dl number is %d
,He visted %f kms with the car
", d3.name, d3.dl, d3.kms);
break;
}
}
return;
}
great
this won't work because after entering driver1 details it will encounter break command ,and the code will end.
you can't print the info of all drivers at once
This is better
#include
#include
struct data
{
int km;
int dlno;
char name[30];
char route[20];
}s[10];
display(struct data s[],int n)
{
for(int i=1;i
@@siddharthchampia5674 Exactly, but if he removes break it will work
@@charlottefx7163 to fayada kya hi huva switch case use karne ka, directly hi likh deta
take n number of drivers using loops
#include
typedef struct driverinfo
{
char name[100];
char lic[50];
char r[100];
float dist;
} Driverinfo;
int main()
{
Driverinfo s[10];
int n;
printf("Enter the number of Drivers
");
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
printf("Enter %d driver name
", i + 1);
scanf("%s", &s[i].name);
printf("Enter the licsene of %d driver
", i + 1);
scanf("%s", &s[i].lic);
printf("Enter the route of the %d driver
", i + 1);
scanf("%s", &s[i].r);
printf("Enter the distance traveel by the %d driver
", i + 1);
scanf("%f", &s[i].dist);
}
printf("*******Drivers info*********
");
printf("NAME\t DLNO\t ROUTE\t DISTANCE
");
for (int i = 0; i < n; i++)
{
printf("%s\t%s\t%s\t%f
", s[i].name, s[i].lic, s[i].r, s[i].dist);
}
return 0;
}
thankyou
/*
0.structure :
1.structure are used to create user defined data types.
2.its usually used to store dissimilar data together.
QUESTION:
3.Write a program using loop in structure?
SOLUTION :-
*/
#include
#include
typedef struct
{
char name[55];
int dl;
char date[20];
char route[80];
float kms;
} details;
int main()
{
int n = 3;
details details[n];
printf("Enter driver details
");
for (int i = 0; i < n; i++)
{
printf("driver:%d
", i + 1);
printf("NAME :");
scanf("
%[^
]s", &details[i].name);
printf("ROUTE :");
scanf("
%[^
]s", &details[i].route);
printf("D.L.NO :");
scanf("%d", &details[i].dl);
printf("D.O.B :");
scanf("
%[^
]s", &details[i].date);
printf("DISTANCE :");
scanf("%f", &details[i].kms);
printf("
");
}
printf("---------------DEATAILS OF DRIVERS---------------
");
for (int i = 0; i < n; i++)
{
printf("DRIVER:%d
", i+1);
printf("NAME\t:%s
", details[i].name);
printf("ROUTE\t:%s
", details[i].route);
printf("D.L.NO\t:%d
", details[i].dl);
printf("D.O.B\t:%s
", details[i].date);
printf("DISTANCE:%f KMS
", details[i].kms);
printf("
");
}
return 0;
}
/*Enter driver details
driver:1
NAME :SONU KUMAR
ROUTE :PATNA TO PUNJAB
D.L.NO :012457884
D.O.B :05/08/1998
DISTANCE :520
driver:2
NAME :RAMESH MISHRA
ROUTE :PUNJAB TO HARYANA
D.L.NO :012457848
D.O.B :24/04/2004
DISTANCE :240
driver:3
NAME :PIYUSH KUMAR
ROUTE :HARYANA TO LUCKNOW
D.L.NO :0123568995
D.O.B :12/06/2003
DISTANCE :540
---------------DEATAILS OF DRIVERS---------------
DRIVER:1
NAME :SONU KUMAR
ROUTE :PATNA TO PUNJAB
D.L.NO :12457884
D.O.B :05/08/1998
DISTANCE:520.000000 KMS
DRIVER:2
NAME :RAMESH MISHRA
ROUTE :PUNJAB TO HARYANA
D.L.NO :12457848
D.O.B :24/04/2004
DISTANCE:240.000000 KMS
DRIVER:3
NAME :PIYUSH KUMAR
ROUTE :HARYANA TO LUCKNOW
D.L.NO :123568995
D.O.B :12/06/2003
DISTANCE:540.000000 KMS
*/
details[n] samaj nehi aya. pls bol do
@@A.De997 jisse n drivers ke info le sakte hio
error ayega, scanf doenst take sapces
i made a function to take user input for driver data. Function takes a struct variable as argument and
returns nothing i am getting an error that my function works well with one variable d1 and then when it is called by d2 it skips
one or two printf and scanf. i dont know why. Harry bhaiya please address this problem. @codeWithHarry
Same problem
My code is -
#include
#include
struct Driver
{
char name[100];
long license_num;
int route;
int km;
};
int main(int argc, char const *argv[])
{
int size;
printf("What is the number of drivers?
");
scanf("%d", &size);
struct Driver driver_list[size];
for (int i = 0; i < size; i++)
{
printf("Enter the name of driver no.%d
", (i+1));
scanf("%s", driver_list[i].name);
printf("Enter the license number of driver no.%d
", (i+1));
scanf("%d", &driver_list[i].license_num);
printf("Enter the route number of driver no.%d
", (i+1));
scanf("%d", &driver_list[i].route);
printf("Enter the number of kilometres of driver no.%d
", (i+1));
scanf("%d", driver_list[i].km);
}
for (int i = 0; i < size; i++)
{
printf("Name of driver %d: %s
", (i+1), driver_list->name);
printf("License number of driver %d: %d
", (i+1), driver_list[i].license_num);
printf("Route no. of driver %d: %d
", (i+1), driver_list[i].route);
printf("Number of kilometres of driver %d: %d
", (i+1), driver_list[i].km);
}
return 0;
}
The output I am getting is -
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Try the new cross-platform PowerShell aka.ms/pscore6
PS C:\Users\Dell\Desktop\C programming VS code> gcc structure_array.c
PS C:\Users\Dell\Desktop\C programming VS code> .\a.exe
What is the number of drivers?
4
Enter the name of driver no.1
Valmik
Enter the license number of driver no.1
672
Enter the route number of driver no.1
5
Enter the number of kilometres of driver no.1
90
PS C:\Users\Dell\Desktop\C programming VS code>
Why isn't the program getting run till the end? Please help.
#include
// Using scanf for string because fgets and gets having issue with input lines
typedef struct Driver {
char name[40];
char dlNo[30];
char route[25];
int kms;
} dr;
int main() {
int n; /// No. of drivers
printf("For how many drivers you want to take details
> ");
scanf("%d",&n);
dr s[n];
//Inputs details
for (int i=0;i
#include
#include
struct details {
char name[50];
char drivinglic[50];
char route[50];
int kms;
};
int main()
{
typedef struct details dtype;
int n;
printf("Enter the numbers of drivers : ");
scanf("%d", &n);
printf("
");
dtype a[n];
for(int i=0; i