I have to write a program in C for a school project that registers a geriatric client, this is my code:
int position=0, correctData=0, day, month, year, phone, iRS, exercises;
float height, weight;
char confirmation, name[100], address[100], numberToCheck[9];
for(int i=0; Client[i]->name!="NULL";i++){
position++;
if(i==30){
break;
}
}
do{
fflush(stdin);
system("cls");
printf("\n\tINSERT NEW CLIENT");
printf("\nInsert client name: ");
gets(name);
printf("\nInsert client address: ");
gets(address);
printf("\nInsert client birthday(dd/mm/yyyy): ");
scanf("%d/%d/%d", &day,&month,&year);
do{
fflush(stdin);
strcpy(numberToCheck, "");
printf("\nInsert client phone number: ");
gets(numberToCheck); //THIS IS THE LINE ERASING MY ADDRESS VARIABLE
if(isPhone(numberToCheck)==0){
printf("\nNumber not valid");
}
}while(phone(numberToCheck)==0);
phone= validateInput(numberToChek);
do{
fflush(stdin);
strcpy(numberToCheck, "");
printf("\nInsert client tax number: ");
gets(numberToCheck);
if(isIRS(numberToCheck)==0){
printf("\nNumber not valid");
}
}while(isIRS(numberTocheck)==0);
iRS= validateInput(numberToCheck);
printf("\nInsert client height: ");
scanf("%f", &height);
printf("\nInsert client weight: ");
scanf("%f", &weight);
printf("\nInsert the number of exercises made: ");
scanf("%d", &exercise);
fflush(stdin);
system("cls");
printf("Name : %s", name);
printf("\nAddress : %s", address);
printf("\nBirthday : %02d/%02d/%04d", dia, mes, ano);
printf("\nPhone number : %d", telefone);
printf("\IRS : %d", contribuinte);
printf("\nHeight and Weight : %.2fm e %.2fKg", height, weight);
printf("\nNumber of exercises : %d", exercise);
printf("\n\nIs the data correct??(Y/N): ");
scanf("%c", &confirmation);
if(confirmation=='Y' || confirmation=='y'){
strcpy(Client[position]->name, name);
strcpy(Client[position]->address, address);
Client[position]->dayBirth = day;
Client[position]->monthBirth = month;
Client[position]->yearBirth = year;
Client[position]->phone = phone;
Client[position]->iRS = iRS;
Client[position]->height= height;
Client[position]->weight= weight;
Client[position]->exercise = exercise;
correctData = 1;
}
}while(correctData==0);
printf("\nUser registered");
printf("\n\nPress Enter to continue");
system("pause >nul /nobreak");
I receive by reference the array Client[100] so that i can modify its elements.
In the part of the code to check if it's a phone number/iRS number i use a pre-coded submodule to validate it.
The problem I'm having with the code is that it stores the address of the client but when the program receives the numberToCheck to check if it is a phone number the address variable is cleaned, becomes empty and I don't see why.
I appreciate any help and time given to help me solve the problem
Related
void addadmin() {
FILE *f;
int menu;
int total;
int hargaTriple = 3000000;
int hargaDoubleBed = 2000000;
int hargaTwin = 1500000;
int hargaSingleBed = 1000000;
int a=0;
int i=0;
time_t t;
time(&t);
char test;
f=fopen("add.txt","a+");
if(f==0) {
f=fopen("add.txt","w+");
system("cls");
printf("Please hold on while we set our database in your computer!!");
printf("\n Process completed press any key to continue!!! ");
getch();
}
while(1) {
system("cls");
for(i=0;i<100;i++)
printf("-");
printf("\n Current date and time : %s",ctime(&t));
for(i=0;i<100;i++)
printf("-");
printf("\n");
for(i=0;i<100;i++)
printf("=");
printf("\n");
printf("\t\t\t\t\t|ROOM RESERVATION|\t\t\t\t\t\n");
for(i=0;i<100;i++)
printf("=");
printf("\n");
printf("\n NAME : ");
fflush(stdin);
scanf("%[^\n]%*c", s.name,20);
printf("\n--------------------------------------------------");
printf("\n GENDER [M/F] : ");
scanf_s("%s", s.gender, 2);
printf("\n--------------------------------------------------");
printf("\n AGE : ");
scanf_s("%d", &s.age);
printf("\n--------------------------------------------------");
printf("\n ADDRESS : ");
fflush(stdin);
scanf("%[^\n]%*c", s.address);
printf("\n--------------------------------------------------");
printf("\n PHONE NUMBER : ");
scanf("%s",s.phonenumber);
printf("\n--------------------------------------------------");
printf("\n NATIONALITY : ");
scanf("%s",s.nationality);
printf("\n--------------------------------------------------");
printf("\n E-MAIL ADDRESS : ");
scanf(" %s",s.email);
printf("\n--------------------------------------------------");
printf("\n ROOM TYPE:");
printf("\n------------------------------");
printf("\n Enter 1 -> EXECUTIVE TRIPLE");
printf("\n------------------------------");
printf("\n Enter 2 -> DOUBLE ROOM");
printf("\n------------------------------");
printf("\n Enter 3 -> TWIN ROOM");
printf("\n------------------------------");
printf("\n Enter 4 -> SINGLE ROOM");
printf("\n------------------------------");
printf("\n Enter your choice: ");
scanf_s("%s", s.typeroom, 10);
printf("\n--------------------------------------------------");
printf("\n NUMBER OF ROOM : ");
scanf_s("%d", &s.numberofroom);
printf("\n--------------------------------------------------");
for(a=0; a<s.numberofroom; a++)
printf("\n ROOM NUMBER : %s",s.roomnumber[a]);
fflush(stdin);
printf("\n--------------------------------------------------");
printf("\n PERIOD [DAYS] : ");
scanf_s("%d", &s.period);
printf("\n--------------------------------------------------");
printf("\n ARRIVAL [DD/MM/YYYY] : ");
scanf("%s",&s.arrivaldate);
for(i=0;i<100;i++)
printf("=");
printf("\n");
printf("\n\n ROOM BOOKING DATA:");
printf("\n--------------------------------------------------");
printf("\n NAME : %s", s.name);
printf("\n--------------------------------------------------");
printf("\n GENDER : %s", s.gender);
printf("\n--------------------------------------------------");
printf("\n AGE : %d", s.age);
printf("\n--------------------------------------------------");
printf("\n ADDRESS : %s",s.address);
printf("\n--------------------------------------------------");
printf("\n PHONE NUMBER : %s",s.phonenumber);
printf("\n--------------------------------------------------");
printf("\n NATIONALITY : %s",s.nationality);
printf("\n--------------------------------------------------");
printf("\n E-MAIL ADDRESS : %s",s.email);
printf("\n--------------------------------------------------");
for(a=0; a<s.numberofroom; a++)
printf("\n ROOM NUMBER : %s",s.roomnumber[a]);
printf("\n--------------------------------------------------");
printf("\n ROOM TYPE : %s", s.typeroom);
printf("\n--------------------------------------------------");
printf("\n NUMBER OF ROOM : %d", s.numberofroom);
printf("\n--------------------------------------------------");
printf("\n PERIOD : %d", s.period);
printf("\n--------------------------------------------------");
printf("\n ARRIVAL : %s",&s.arrivaldate);
printf("\n--------------------------------------------------");
I've tried to change roomnumber to numberofrooms but the output is just repetitive room number. The roomnumber was supposed to contain the room numbers but from what I understand, the roomnumber array is just a blank/empty array. So, how to change the output from null to number of rooms that i wanted?
I am having problem with appending more records to this file. It allows me add just one record but I cannot add more than one record. And cannot figure out what is going wrong with it?
void new_customer()
{
char ch;
int flag=0;
FILE *fp;
fp=fopen("DataFile.txt", "a+");
printf("Enter today's date (dd/mm/yyyy) : ");
scanf(" %d/%d/%d", &add.deposit.day, &add.deposit.month, &add.deposit.year);
printf("Enter Account Number : ");
fflush(stdin);
scanf("%ld", &check.account_number);
while(fscanf(fp, "%ld %s %s %s %s %s %d %d/%d/%d %d %d/%d/%d %c", &add.account_number, add.customer_name, add.father_name, add.address, add.Nationality, &add.p_number, &add.age, &add.dob.day, &add.dob.month, &add.dob.year, &add.amount, &add.deposit.day, &add.deposit.month, &add.deposit.year, &add.account_type)!=EOF)
{
if(check.account_number==add.account_number)
{
printf("Account number already taken. Please contact administrator.\nPress enter to continue.");
getch();
system("cls");
main();
}
}
add.account_number=check.account_number;
printf("Enter name : ");
fflush(stdin);
gets(add.customer_name);
printf("Enter Father's name : ");
fflush(stdin);
gets(add.father_name);
printf("Enter your age : ");
fflush(stdin);
scanf("%d", &add.age);
printf("Enter Date of birth (dd/mm/yyyy) : ");
scanf("%d/%d/%d", &add.dob.day, &add.dob.month, &add.dob.year);
printf("Enter Phone Number : ");
fflush(stdin);
gets(add.p_number);
printf("Enter Nationality : ");
fflush(stdin);
gets(add.Nationality);
printf("Enter Address : ");
fflush(stdin);
gets(add.address);
printf("Enter Account Type:\nPress S for Savings, \nPress C for Current, \nF for Fixed : ");
fflush(stdin);
scanf("%c",&add.account_type);
while(flag!=1)
{
if (add.account_type=='S'|| add.account_type=='s'||add.account_type=='C'||add.account_type=='c'||add.account_type=='F'||add.account_type=='f')
{
flag=1;
}
else
{
printf("\nWrong Input. Input Again : ");
fflush(stdin);
scanf("%c", &add.account_type);
flag=0;
}
}
printf("Deposit Amount : ");
fflush(stdin);
scanf("%d", &add.amount);
fprintf(fp, "%ld %s %s %s %s %s %d %d/%d/%d %d %d/%d/%d %c\n", add.account_number, add.customer_name, add.father_name, add.address, add.Nationality, add.p_number, add.age, add.dob.day, add.dob.month, add.dob.year, add.amount, add.deposit.day, add.deposit.month, add.deposit.year, add.account_type);
printf("\nAccount Created Successfully!!\n");
fclose(fp);
while(1)
{
printf("Return to Main Menu? Y/N : ");
fflush(stdin);
scanf("%c", &ch);
if(ch=='Y' || ch=='y')
{
system("cls");
main();
}
else if(ch=='N' || ch=='n')
{
exit(0);
}
else
{
printf("\nWrong input. Try Again!\n");
}
}
}
This is just a function to a big program. I am attaching just the part which includes file handling. If you want I can attach more code.
Here I am adding the main driver code
#include<windows.h>
#include<stdio.h>
#include<stdlib.h>
#include "E:\Projects\C Language\Bank-Management-System\File Containing Functions.c"
int menu(void);
int gotoxy(int x, int y)
{
COORD c;
c.X=x;
c.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c);
}
int menu()
{
int i, a;
gotoxy(40,0);
printf("BANK MANAGEMENT SYSTEM\n");
gotoxy(43, 3);
printf(":: MAIN MENU ::\n");
gotoxy(40, 5);
printf("[1] Create a new account");
gotoxy(40, 6);
printf("[2] Update information of existing account");
gotoxy(40, 7);
printf("[3] Transactions");
gotoxy(40, 8);
printf("[4] Check details of existing account");
gotoxy(40, 9);
printf("[5] Remove existing account");
gotoxy(40, 10);
printf("[6] View Customer List");
gotoxy(40, 11);
printf("[7] Exit\n");
gotoxy(40, 15);
printf("Enter your choice : ");
scanf("%d", &a);
return a;
}
int main()
{
int choice;
choice=menu();
switch(choice)
{
case 1:
{
system("cls");
new_customer();
break;
}
case 3:
{
system("cls");
transaction();
break;
}
case 7 :
{
system("cls");
printf("Thank You for using our services!!");
exit(0);
}
default:
{
printf("Wrong Input!!\n");
getch();
system("cls");
menu();
}
}
getch();
return 0;
}
Link to see input : https://pasteboard.co/Jt3xWrP.jpg
Here is the file after first input : https://pasteboard.co/Jt3yYA9.jpg
Another input :https://pasteboard.co/Jt3yHSC.jpg (this is where it gets stuck forever and doesn't let me add another record)
Text stored inside file :
123 John Papa John 15, Yemen Road, Yemen USA 12345678 22 11/2/0 2000 27/9/2020 S
So to start with the file holds:
123 John Papa John 15, Yemen Road, Yemen USA 12345678 22 11/2/0 2000 27/9/2020 S
And you try to scan it with
fscanf(fp, "%ld %s %s %s %s %s %d %d/%d/%d %d %d/%d/%d %c"
That is:
1 number
5 strings
1 number
...
As you can see, the file doesn't match that.
123 John Papa John 15, Yemen Road, Yemen USA 12345678 22 11/2/0 2000 27/9/2020 S
^^^ ^^^ ^^^ ^^^ ^^^ ^^^ ^^^
ok ok ok ok ok ok Not ok, so stop here
The next fscanf will not match anything (it expects a number but the file has "Road") so nothing is read.
In other words, you are stuck in the while forever.
I'll recommend reading the file in a line by line manner using fgets.
Then you can (in principle) use sscanf afterwards. But notice that %s reads a single word and your code allow multiple words for a single entry! In other words - your file can't be parsed using %s.
So consider another file format. For instance, you could use 1 line for each item in a record. That will make parsing much easier.
This question already has answers here:
Why scanf must take the address of operator
(8 answers)
Closed 2 years ago.
Below is my code.
For simplicity I made the code to take the info about 2 friends for now.
But the problem is my for loop in getting user input.
It only works if I remove this part here
printf("Enter Age: ");
scanf("%d", friends[a].age);
here is the full for-loop
for(a=0; a<2; a++) {
printf("Friend no. %d\n", friends[a].fnum+1);
printf("Enter Name: ");
gets(friends[a].name);
printf("Enter Town: ");
scanf("%s", friends[a].address);
printf("Enter Age: ");
scanf(" %d", friends[a].age);
printf("Enter Course: ");
scanf(" %s", friends[a].course);
printf("Favorite foods! \n");
printf("Dish:");
scanf(" %s", friends[a].fav_dish);
printf("Snack:");
scanf(" %s", friends[a].fav_snack);
printf("Drink:");
scanf(" %s", friends[a].fav_drink);
printf("\n");
}
At first, I thought it was the age part was the problem, so I brought it last. But it did not solve it.
I thought it was the scanf too, so I added a space in scanf(" %s", friends[a].course); But nothing work.
I also tried this
printf("Enter Age: ");
scanf(" %d\n ", friends[a].age);
so I tried deleting
printf("Enter Age: ");
scanf("%d", friends[a].age);
and the loop continued to friend 2
What should I do?
Here is my full source code:
#include <string.h>
struct myFriends {
char name[30];
char address[20];
int age;
char course[20];
char fav_dish[20], fav_snack[20], fav_drink[20];
}; struct myFriends friends[2];
int main () {
int a;
puts("Please enter the following info for 2 friends");
for(a=0; a<2; a++) {
printf("Friend no. %d\n", a+1);
printf("Enter Name: ");
scanf("%s", friends[a].name);
printf("Enter Town: ");
scanf("%s", friends[a].address);
printf("Enter Age: ");
scanf(" %d\n ", friends[a].age);
printf("Enter Course: ");
scanf(" %s", friends[a].course);
printf("Favorite foods! \n");
printf("Dish:");
scanf(" %s", friends[a].fav_dish);
printf("Snack:");
scanf(" %s", friends[a].fav_snack);
printf("Drink:");
scanf(" %s", friends[a].fav_drink);
printf("\n");
}
printf("Here are the details");
for (a=0; a<2; a++) {
printf("\n\n Friend no. %d", a+1);
printf("Name:");
puts(friends[a].name);
printf("Town: ");
puts(friends[a].address);
printf("Age: ");
printf("%d", friends[a].age);
printf("Fave FOODS!: ");
puts(friends[a].fav_dish);
puts(friends[a].fav_snack);
puts(friends[a].fav_drink);
}
return 0;
}
In here, I add & mark to pass pointers to scanf, so try this. I hope this works for you.
#include
#include <stdio.h>
#include <string.h>
struct myFriends {
char name[30];
char address[20];
int age;
char course[20];
char fav_dish[20], fav_snack[20], fav_drink[20];
}; struct myFriends friends[2];
int main () {
int a;
puts("Please enter the following info for 2 friends");
for(a=0; a<2; a++) {
char name[30];
char address[20];
int age;
char course[20];
char fav_dish[20], fav_snack[20], fav_drink[20]
printf("Friend no. %d\n", a+1);
printf("Enter Name: ");
scanf("%s", &name);
friends[a].name=name;
printf("Enter Town: ");
scanf("%s", &address);
friends[a].address=address;
printf("Enter Age: ");
scanf(" %d\n ", &age);
friends[a].age=age;
printf("Enter Course: ");
scanf(" %s", &course);
friends[a].course=course;
printf("Favorite foods! \n");
printf("Dish:");
scanf(" %s", &fav_dish);
friends[a].fav_dish=fav_dish;
printf("Snack:");
scanf(" %s", &fav_snack);
friends[a].fav_snack=fav_snack;
printf("Drink:");
scanf(" %s", &fav_drink);
friends[a].fav_drink=fav_drink;
printf("\n");
}
printf("Here are the details");
for (a=0; a<2; a++) {
printf("\n\n Friend no. %d", a+1);
printf("Name:");
puts(friends[a].name);
printf("Town: ");
puts(friends[a].address);
printf("Age: ");
printf("%d", friends[a].age);
printf("Fave FOODS!: ");
puts(friends[a].fav_dish);
puts(friends[a].fav_snack);
puts(friends[a].fav_drink);
}
return 0;
}
I am trying to write some records (patient info) into a .dat file using c. The patient info contains the National ID no., name, gender and the telephone no.
Here's my code:
#include<stdio.h>
int main(void)
{
char order = 'y';
int nic = 0; // NIC no.
char name[] = "xxx"; // name
char gender = 'x'; // Patients' gender
int tel_no = 0; // telephone no.
FILE *fp;
fp = fopen("patientdetails.dat", "w"); // Creat patientdetails file
if (fp == NULL)
{
printf("Cannot open file\n");
return -1;
}
else
{
printf("Do you want to enter a record (y/n): ");
scanf("%c", &order);
while (order == 'y' || order == 'Y')
{
printf("Enter nic no.: ");
scanf("%d", &nic);
printf("Enter name: ");
scanf("%s", name);
printf("Enter gender (m/f): ");
scanf(" %c", &gender);
printf("Enter tel no.: ");
scanf("%d", &tel_no);
fprintf(fp, "%d %s %c %d\n", nic, name, gender, tel_no);
printf("Do you want to enter a record (y/n): ");
scanf(" %c", &order);
}
fclose(fp);
}
return 0;
}
However when I enter the following info into my .dat file in the terminal:
Do you want to enter a record (y/n): y
Enter nic no.: 200007102766
Enter name: Timothy
Enter gender (m/f): m
Enter tel no.: 0779428897
Do you want to enter a record (y/n): n
There is an error in the integers, namely nic no. and telephone no.
Additionally I made another program to read the file, the error in the integers still seem to show up.
Errors in the .dat file:
7956596 Timothy m 779428897
I can't seem to figure out how to correct the integer errors,
where 20007102766 is shown as 7956596
and 0779428897 is shown as 779428897.
Any help is appreciated!
Your variable byte size is larger than a int, so you should use bigger variable type.
In your example, you can use long type for nic and tel_no veriables.
Also you should use %ld in format, otherwise it gives you warning.
char order = 'y';
long nic = 0; // NIC no.
char name[] = "xxx"; // name
char gender = 'x'; // Patients' gender
long tel_no = 0; // telephone no.
And while formating
printf("Enter nic no.: ");
scanf("%ld", &nic);
printf("Enter tel no.: ");
scanf("%ld", &tel_no);
fprintf(fp, "%ld %s %c %ld\n", nic, name, gender, tel_no);
I'm trying to simply read input from the user and store a CD record into some variables. All the variables details are correctly printed out for all the variables except for the second array of char for artist which isn't printing anything. I've tried to deal with the extra character spacing by introducing the space at the front of each of my formatted strings in scanf(), but that hasn't fixed it.
void displayCDInfo(char* title, char* artist, short noOfTracks, int isAlbum, float price);
int main()
{
char title[61];
char artist[41];
short noOfTracks = 0;
int isAlbum = 0;
float price = 0.0;
char albumOrSingleResponse;
printf("Please enter the title: ");
scanf(" %s", title);
printf("Please enter the artist: ");
scanf(" %s", artist);
printf("Please enter the number of records: ");
scanf(" %d", &noOfTracks);
printf("Please enter whether or not the cd is an album/single (A or S): ");
scanf(" %c", &albumOrSingleResponse);
if(albumOrSingleResponse == 'A')
{
isAlbum = 1;
}
printf("Please enter the price of the CD: ");
scanf(" %f", &price);
displayCDInfo(title, artist, noOfTracks, isAlbum, price);
return 0;
}
void displayCDInfo(char* title, char* artist, short noOfTracks, int isAlbum, float price)
{
printf("\nThe title of the CD is %s", title);
printf("\nThe name of the artist is %s", artist);
printf("\nThe number of tracks on this CD are %d", noOfTracks);
printf("\nThe CD is an %s", (isAlbum == 1) ? "album" : "single");
printf("\nThe price of the cd is $%.2f", price);
}
This will work. Just move the position of char array declaration from top of main body.
void displayCDInfo(char* title, char* artist, short noOfTracks, int isAlbum, float price);
int main()
{
short noOfTracks = 0;
int isAlbum = 0;
float price = 0.0;
char albumOrSingleResponse;
char title[61];
char artist[41];
printf("Please enter the title: ");
scanf(" %s", title);
printf("Please enter the artist: ");
scanf(" %s", artist);
printf("Please enter the number of records: ");
scanf(" %d", &noOfTracks);
printf("Please enter whether or not the cd is an album/single (A or S): ");
scanf(" %c", &albumOrSingleResponse);
if(albumOrSingleResponse == 'A')
{
isAlbum = 1;
}
printf("Please enter the price of the CD: ");
scanf(" %f", &price);
displayCDInfo(title, artist, noOfTracks, isAlbum, price);
return 0;
}
void displayCDInfo(char* title, char* artist, short noOfTracks, int isAlbum, float price)
{
printf("\nThe title of the CD is %s", title);
printf("\nThe name of the artist is %s", artist);
printf("\nThe number of tracks on this CD are %d", noOfTracks);
printf("\nThe CD is an %s", (isAlbum == 1) ? "album" : "single");
printf("\nThe price of the cd is $%.2f", price);
}
I figured out how to fix this now whilst keeping noOfTracks as a short. Since I was using "%d" for scanf on the Number of tracks variable I was overwriting the space allocated for the previous variable which was artist, hence why it wasn't being displayed. To solve this I had to change the "%d" to "%hu" for short int.
void displayCDInfo(char* title, char* artist, short noOfTracks, int isAlbum, float price);
int main()
{
char title[61];
char artist[41];
short noOfTracks = 0;
int isAlbum = 0;
float price = 0.0;
char albumOrSingleResponse;
printf("Please enter the title: ");
scanf("%s", title);
printf("Please enter the artist: ");
scanf("%s", artist);
printf("Please enter the number of records: ");
scanf("%hu", &noOfTracks);
printf("Please enter whether or not the cd is an album/single (A or S): ");
scanf(" %c", &albumOrSingleResponse);
if(albumOrSingleResponse == 'A')
{
isAlbum = 1;
}
printf("Please enter the price of the CD: ");
scanf(" %f", &price);
displayCDInfo(title, artist, noOfTracks, isAlbum, price);
return 0;
}
void displayCDInfo(char* title, char* artist, short noOfTracks, int isAlbum, float price)
{
printf("\nThe title of the CD is %s", title);
printf("\nThe name of the artist is %s", artist);
printf("\nThe number of tracks on this CD are %hu", noOfTracks);
printf("\nThe CD is an %s", (isAlbum == 1) ? "album" : "single");
printf("\nThe price of the cd is $%.2f", price);
}
Remove the space: scanf("%s", ...) and add a space: scanf(" %c", ..)
int main()
{
char title[61];
char artist[41];
short noOfTracks = 0;
int isAlbum = 0;
float price = 0.0;
char albumOrSingleResponse;
printf("Please enter the title: ");
scanf("%s", title);
printf("Please enter the artist: ");
scanf("%s", artist);
printf("Please enter the number of records: ");
scanf("%hu", &noOfTracks);
printf("Please enter whether or not the cd is an album/single (A or S): ");
scanf(" %c", &albumOrSingleResponse);
if(albumOrSingleResponse == 'A')
{
isAlbum = 1;
}
printf("Please enter the price of the CD: ");
scanf("%f", &price);
displayCDInfo(title, artist, noOfTracks, isAlbum, price);
return 0;
}
Because when you add a space before " %c" it consumes newline characters entered with previous inputs.
Edit: From this, you may use "%hu" for printing the short to avoid any warning.