Peter V5
Folding Member
Olá, nunca conssegui comparar strings em C com um if, tipo desta maneira:
Dá sempre que não deu, então tentei fazer eu uma função para isso, fiz:
Código:
#include <stdio.h>
#include <string.h>
main()
{[INDENT] char x[10], y[10];
gets(x);
gets(y);
if(x == y)[INDENT] printf("São iguais");
[/INDENT]else[INDENT] printf("Não são iguais");
[/INDENT]getchar();
getchar();
[/INDENT]}
Código:
#include <stdio.h>
#include <string.h>
int compare(char x[20], char y[20])
{[INDENT]int i;
for(i=0; i<20; i++)
{[INDENT]if(x[i] != y[i])[INDENT]return 0;
[/INDENT]if(x[i] == '\'' && x[i+1] == '0')[INDENT]return 1;
[/INDENT][/INDENT]}
[/INDENT]}
main()
{[INDENT]char x[20], y[20];
int sim;
printf("Insira duas strings\n");
gets(x);
gets(y);
sim = compare(x, y);
if(sim == 1)[INDENT]printf("São iguais\n");
[/INDENT]else[INDENT]printf("Não\n");
[/INDENT]getchar();
getchar();
[/INDENT]}
Última edição pelo moderador: