c - 错误: Expected Expression '/' before token

标签 c

这是我的 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);
}

最佳答案

  1. 我认为,scanf("%c",&more);应该是scanf("%c",&type);
  2. 您失踪了;puts(album[i]?"Album":"Single")
  3. 您失踪了#include <ctype.h>对于 toupper()功能

经过这些更改后,我能够在 Visual studio 2005 中正确编译并运行该程序(看起来)。

关于c - 错误: Expected Expression '/' before token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29077281/

相关文章:

c - 以编程方式确定程序是否正在运行

c - 需要帮助编译一些东西! ( :

命令行参数写入 make 文件

c - 用于 stalonetray 的 Linux XCB dockapp 软件

c - 是否可以在 C 中捕获 Enter 按键?

java - 开始 Activity 但在后台

c - 为什么 strcat 会导致崩溃?

c++ - 如何在 Windows 上为 NetBeans 和 gcc 添加库包含路径?

c - 如何在 openGL 中加载 png 图像并使用鼠标移动它?

c - 使用 exec 程序从父级读取和写入多个子级