c - 我不明白的指针警告
问题描述
我尝试将用户引导到不同的论坛,然后让他选择一个区块。但是我在编译时有几个错误,我不熟悉我的指针。
#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) ;
解决方案
改变这个:
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
以指示两个参数之间的相等性。
推荐阅读
- python - Python中的高斯拟合
- macos - Android模拟器启动使Mac无响应
- date - ga:YearWeek 与 =isoweeknum 不同
- r - 如何在 purrr 中使用 rlang
- docker - 为什么我不能简单地从我的 Windows 主机 ssh 到 docker 容器?
- xamarin.forms - 我可以创建一些小视图,包括创建的视图以在 mainPage 中使用它吗?
- flask - Jinja2 - 表达式连接问题
- colors - SwiftUI:VStack 不适用于白色背景颜色,但适用于所有其他颜色
- python - 如何从 API 更改用户的密码
- r - R lpsolve 获得第 2、第 3、第 N 个最佳解决方案