首页 > 解决方案 > 我不明白的指针警告

问题描述

我尝试将用户引导到不同的论坛,然后让他选择一个区块。但是我在编译时有几个错误,我不熟悉我的指针。

#include <stdio.h>
#include <string.h>

#define MAX_NOM 10 

typedef struct Place {
    char seat[15] ; 
}Place; 

typedef struct Rang{
    int rang        ; 
    Place une_place ; 
}Rang; 

typedef struct Bloc {
    int bloc     ; 
    Rang un_rang ; 
}Bloc; 

typedef struct Stade {

    char nom[MAX_NOM]     ; 
    char tribune[MAX_NOM] ;
    Bloc un_bloc          ; 
}Stade; 

int main()
{

    int numbloc = 0  ; 
    Stade unstade ; 
    Bloc unbloc[21];
    Rang unrang[4];
    Place uneplace[99];

 printf("Nom de la tribune         :")       ;
 scanf("%s", &unstade.tribune)               ;
 
 if(strcmp(unstade.tribune, "Nord" == "1" ))
 {
    // printf("Dans quel bloc voulez-vous réserver une place : ")   ; 
    // scanf("%d", &numbloc)                                        ;

    // while ((numbloc < 0) & (numbloc >21) )
    // {
    //     printf("Merci de saisir un numéro de bloc entre 0 et 22")  ; 
    // }
 }
 else if (strcmp(unstade.tribune, "Sud" == "1" ))
 {
     printf("SUUUUD"); 

 }
 else if(strcmp(unstade.tribune, "Est" == "1"))
 {
     printf("ESSSST") ; 

 }
 else if (strcmp(unstade.tribune, "Ouest" == "1" ))
 {
     printf("OUESSST") ; 
 }
 else{
     printf ("Le nom de la tribune doit être Nord, Sud, Est ou Ouest") ;
 }

}



我不知道是不是因为 scanf("%s", &unstade.tribune) ; 或
scanf("%s", unstade.tribune) ; 我有这个消息

标签: c

解决方案


改变这个:

scanf("%s", &unstade.tribune);

对此:

scanf("%s", unstade.tribune);

格式说明%s符需要一个 char 数组或 char 指针,但不是指向数组的指针。

这不是您比较字符串是否相等的方式:

if(strcmp(unstade.tribune, "Nord" == "1" ))

但这是:

if (strcmp(unstade.tribune, "Nord") == 0)

strcmp返回一个整数0以指示两个参数之间的相等性。


推荐阅读