数组和"警告:格式'%s'期待匹配的char *'参数[-Wformat =]"

时间:2015-08-29 05:36:52

标签: c arrays string-formatting

我在学校为一个项目制作了这个项目,但由于以下原因无法正常运行:

  

警告:格式'%s'期待匹配的char *'参数[-Wformat =]

注意:我们几乎没有开始学习数组,所以请耐心等待。

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#define p printf
#define s scanf
    int ctr,select,car_in,car_type;
    int a,d,e;
    double t_in[100];
    int car[100],fee=30;
    char plate[100];
int main(){
    a=0;
    d=0;
    e=0;
    start:
p("     A program that will store parking details into array until exit\n\n");
  for(ctr=0;ctr<=14;ctr++)                                     {/*St_Max car loop*/
    p("\t\t  [1] Enter Vehicle  [2] Exit Vehicle\n\n");{
    p("\n\n\n\t\t\t\tChoose: ");
     s("%d",&select);
    if(select==2)
        {goto exit;}
    else if(select==1)
        {goto enter;}
    else{p("ERROR!!");
        system("cls");
        return main();}}
enter:                                               /*St_Park*/
    system("cls");
    p("\n\t     [1] Car 30 [2] SUV 35 [3] Van 40 [4] Motorcycle 25\n\n");
    p("\t   -------------------------------------------------------\n\n");
    p("Receipt number: %d",a);
    p("\n\nVehicle Type: ");
     s("%d",&car_type);
    p("\nPlate number: ");
     s("%s",&plate[d]);
    p("\nTime in(24h): ");
     s("%lf",&t_in[e]);
     a++;
     d++;
     e++;
switch (car_type){                                  /*Parking fee range*/
    case 1:
        p("\nParking Fee: %3.2d",fee);
        break;
    case 2:
        p("\nParking Fee: %3.2d",fee+=5);
        break;
    case 3:
        p("\nParking Fee: %3.2d",fee+=10);
        break;
    case 4:
        p("\nParking Fee: %3.2d",fee-=5);
        break;
    default:
        p("\n\n\t\t\t\tERROR !!");
        a--;}
    getch();
    system("cls");
  goto start;                /*Return main*/
exit:                                           /*Release vehicle*/
    system("cls");
    p("\n\n\n\t\tReciept number: ");
     s("%d",&car_in);p("\n\t\t-------------------------------\n");
     e=d=car_in;
    p("\n  Plate number: %s",plate[d]);
    p("\n\n  Time in: %lf",t_in[e]);
    p("\n\n  Parking Fee: %d",fee);
    getch();
    system("cls");
    return main();              }/*Ed_Max car loop*/
    return 0;
}

1 个答案:

答案 0 :(得分:0)

 p("\n  Plate number: %s",plate[d]);

您在此声明中传递的参数会导致问题。使用%c说明符 -

p("\n  Plate number: %c",plate[d]);

修改

您要求阅读来自stdin的字符串,您应该使用fgets -

fgets(plate,sizeof plate,stdin);

这将读取完整的字符串。