[英]online compiler(online gdb)works correctly while g++ and gcc on windows 10 cmd doesn't work when comparing strings
When I compare 2 strings in the website "online gdb", if the comparison is equal it gives 10, if it's not it doesn't give 10(It's already weird that it gives 10 instead of 0, but it works so I didn't care).当我在网站“在线 gdb”中比较 2 个字符串时,如果比较相等,则给出 10,如果不相等,则不给出 10(它给出 10 而不是 0 已经很奇怪了,但它有效,所以我没有'不在乎)。 But since I tried to compile my code with g++ or gcc(I tried with -g too for both)it gives -1 or 1, or only 1, but never 0. Thanks to everyone which will read this code and will help me.
但是由于我尝试使用 g++ 或 gcc 编译我的代码(我也尝试使用 -g 来编译它们)它给出了 -1 或 1,或者只有 1,但从来没有 0。感谢所有阅读这段代码并帮助我的人。
#include <stdio.h>
#include <math.h>
#include <string.h>
int main()
{
char v1q[55], v2q[55], v3q[55], v4q[55];
float v1, v2, v3, v4, vr, min, max;
int comparison;
int v3b = 1;
printf("Per la prima banda non esiste l'oro e l'argento;\nPer la seconda banda non esiste l'oro e l'argento;\nPer la terza banda non esiste il bianco;\nPer la quarta banda esistono SOLO il bianco, oro e argento.\n\n");
printf("Prima cifra: ");
fgets(v1q, sizeof(v1q), stdin);
if(strcmp(v1q, "nero") == 0)
{
printf("\nNon esiste un valore per il nero, per la prima banda");
}
if(strcmp(v1q, "marrone") == 0)
{
v1 = 10;
}
if(strcmp(v1q, "rosso") == 0)
{
v1 = 20;
}
if(strcmp(v1q, "arancione") == 0)
{
v1 = 30;
}
if(strcmp(v1q, "giallo") == 0)
{
v1 = 40;
}
if(strcmp(v1q, "verde") == 0)
{
v1 = 50;
}
if(strcmp(v1q, "blu") == 0)
{
v1 = 60;
}
if(strcmp(v1q, "viola") == 0)
{
v1 = 70;
}
if(strcmp(v1q, "grigio") == 0)
{
v1 = 80;
}
if(strcmp(v1q, "bianco") == 0)
{
v1 = 90;
}
if(strcmp(v1q, "oro") == 0)
{
printf("\nNon esiste un valore per l'oro, per la prima banda");
}
if(strcmp(v1q, "argento") == 0)
{
printf("\nNon esiste un valore per l'argento, per la prima banda");
}
comparison = strcmp(v1q, "marrone");
printf("%d", comparison);
}
In the end I just replaced fgets with scanf, and now it works... I don't know why I didn't do that from the start最后我只是用 scanf 替换了 fgets,现在它可以工作了......我不知道为什么我没有从一开始就这样做
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.