这是我的C程序。我在代码中遇到错误,我无法调试。帮助我找到解决方案。我收到了这个错误:期待表达' /'主函数第一行中的标记
#include <stdio.h>
#include <string.h>
#define NUM_CDS 100
#define TITLE_SIZE 70
#define ARTIST_SIZE 70
int main()
{
/**Declaration of variables**/
char title[NUM_CDS][TITLE_SIZE + 1]; ///Two dimensional Array with row size 100 and col size of 70
#ifndef NOARTIST
char artist[NUM_CDS][ARTIST_SIZE]; ///Array with size 70
#endif
int tracks[NUM_CDS]; ///Available tracks in the CD
char type; ///Type of the CD Whether it is single or album
int album[NUM_CDS];
float price[NUM_CDS];
int count = 0; ///How many CD's are being tracked.
int i;
/// char more;
puts(" Welcome to the CD shop ");
printf(" You can store a maximum of %d CD's.",sizeof price/sizeof price[0]);
puts("======================================");
fflush(stdin);
/**
** Loop until they no longer need more CD's
**/
for(;;) ///Forever loops are convenient for this sort of things
{
/*** Program now asks the user for more entries ***/
puts("Do you want store more data, Enter Y for yes or N for no: ");
fflush(stdin);
scanf("%c",&more);
if( toupper (type) != 'Y') ///if the user input is not equal to Y or y then the loop break
break;
printf("\n"); /** for good practice we use new line **/
///puts(more == 'y'|| more == 'Y'? : break);
///Title Details
fputs("Enter the Title of the CD : ",stdout);
fflush(stdin);
fgets(title[count],sizeof title[count],stdin);
title[count][strlen(title[count])-1]= '\0';
#ifndef NOARTIST
///Artist details
fputs("Artist ?? of the CD : ",stdout);
fflush(stdin);
fgets(artist[count],sizeof artist[count],stdin);
artist[count][strlen(artist[count])-1]= '\0';
#endif
///Tracks Details
printf("How many Tracks are in it : ");
fflush(stdin);
scanf("%d",&tracks[count]);
///Asking the user whether it is album or single
for(;;) ///Exits the loop onli if valid entry is made
{
printf("Album or Single(Press 'a' for Album or 's' for single): ");
fflush(stdin);
scanf("%c",&type);
type = toupper(type);
///only the Valid characters {a,A,s,S} are accepted
if(type == 'a' || type == 's' || type == 'A' || type == 'S')
break;
else
{
printf("Invalid Entry Re-Enter.Valid Entry is a,s,A,S.\n");
///fflush(stdin);
}
}
album[count] = type == 'A';
///Asking user for price.
printf("Price of the CD in Dollars ( Enter in this format 6.30) : ");
fflush(stdin);
scanf("%f",&price[count]);
///count += 1; /// increment the count and start next if prompted
/** check if we have filled in the Array of 100 elements **/
if (++count == NUM_CDS)
{
printf("We have reached maximun limit of size\n\n");
break;
}
}
/*** This is where the output section begins ***/
for(i=0;i<count;i++)
{
printf("\nThe Details of CD %d is : \n",i+1);
puts("==============================");
printf("Title : %s\n",title[i]);
#ifndef NOARTIST
printf("Artist : %s\n",artist[i]);
#endif
printf("Tracks : %d\n",tracks[i]);
puts(album[i]?"Album":"Single")
printf("Price(USD) : %0.2f \n",price[i]);
printf("=============================\n");
/** this block is for user convinence only if more CDs are there **/
if(i < count - 1)
{
printf("Enter to see next CD\n\n");
fflush(stdin);
}
}
printf(" Thank you .Press enter to EXIT \n");
fflush(stdin);
}
答案 0 :(得分:3)
scanf("%c",&more);
应为scanf("%c",&type);
;
puts(album[i]?"Album":"Single")
#include <ctype.h>
函数toupper()
醇>
在这些更改之后,我能够在Visual Studio 2005中正确编译并运行该程序(看起来那样)。