Hello senior programmers! I am new in programming. I am having trouble making my program run efficiently. My code works perfectly fine when I do not give white space. But when I give white space while writing the name or route it doesn't work.
Example: Driver's Name: ALI
( work perfectly )
Example: Driver's Name: ALI ALI
( not working )
I want to write all the char with white space. I have already tried every possible way. I have commanded all the ways which I have tried. I am a beginner. It is my college assignment. Kindly, please help me, How can I fix this?
/*
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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#define Max_Size 1000
#define max 1000
struct Drivers
{
char Name[150];
char Driving_License_No[150];
char Route[150];
char Kms[50];
int positionNo;
} drivers[Max_Size];
int main()
{
int totalDrivers;
char name[200];
printf("Enter the total numbers of drivers\n");
scanf("%d", &totalDrivers);
for (int i = 0; i < totalDrivers; i++)
{
drivers[i].positionNo=i+1;
printf("\nFor Driver Id no. %d,\n", drivers[i].positionNo);
printf("Enter the full name: ");
scanf("%s", &drivers[i].Name);
// scanf("%[^\n]",drivers->Name);
// scanf("%[^\n]s",drivers->Name);
// fgets(drivers.Name, 150, stdin);
// gets(Name);
// gets(driver.Name);
printf("Enter the Driving License no : ");
scanf("%s", &drivers[i].Driving_License_No);
printf("Enter the Driving Route : ");
scanf("%s", &drivers[i].Route);
printf("Enter the Driving KM's : ");
scanf("%s", &drivers[i].Kms);
}
printf("The Information of all drivers are given below\n");
for (int i = 1; i < totalDrivers; i++)
{
printf("\nDriver Id no.: %d\n", i + 1);
printf("Driver's Name: ");
puts(drivers[i].Name);
printf("Driving License no: %s", drivers[i].Driving_License_No);
printf("\n");
printf("Driving Route: %s", drivers[i].Route);
printf("\n");
printf("Driving KM's: %s", drivers[i].Kms);
printf("\n");
}
return 0;
}