数组和 "warning: format '%s' expects a matching 'char *' argument [-Wformat=]"

Array and "warning: format '%s' expects a matching 'char *' argument [-Wformat=]"

我一直在为学校的一个项目制作这个程序,但不能 运行 正确,因为:

warning: format '%s' expects a matching 'char *' argument [-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;
}
 p("\n  Plate number: %s",plate[d]);

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

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

编辑

您要求从 stdin 中读取一个字符串,您应该使用 fgets-

fgets(plate,sizeof plate,stdin);

这将读取完整的字符串。