Hi guys I started to practice C programming a few days ago, and I was asked by the tutorial video to write a program for a CD database. My problem is my code executes the next two printf statements if I enter words separated by a space, is it because of my scanf syntax? Any help is greatly appreciated.
Code:
#include <iostream>
int main()
{
char title[40], artist[40], as[2];
int price, tracks;
printf ("CD DATABASE\n");
printf ("PLEASE ENTER THE TITLE OF THE CD\n");
scanf ("%s", &title);
printf ("PLEASE ENTER THE NAME OF THE ARTIST\n");
scanf ("%s", &artist);
printf ("PLEASE ENTER THE NUBER OF TRACKS\n");
scanf ("%d", &tracks);
printf ("PLEASE TYPE (a) FOR ALBUM AND (s) FOR SINGLE\n");
scanf ("%s", &as);
printf ("PLEASE ENTER THE PRICE OF THE CD\n");
scanf ("%d", &price);
printf ("=====CD INFORMATION=====\n");
printf ("CD TITLE: %s\n", title);
printf ("ARTIST: %s\n", artist);
printf ("NUMBER OF TRACKS: %d\n", tracks);
if (strcmp(as,"a") == 0)
{
printf ("TYPE: ALBUM \n");
}
else
{
printf ("TYPE: SINGLE \n");
}
printf ("PRICE: %d\n", price);
printf ("=====CD INFORMATION=====\n");
fflush (stdin);
getchar ();
}