ahojte,
mam pole: char slovo[256], ve kterem je nejake slovo
muzete mi prosim poradit jak npsat podminku, jak toto pole porovnat s jinym napr. slovo1[256]
a kdyz je obsah stejny tak neco vykonat
vim ze je to hloupy dotaz, ale jsem zacatecnik :-)
Fórum › C / C++
Porovnani dvou poli

prejdes pole a porovnavas
char slovo[256];
char slovo1[256];
bool match = true;
for (int i = 0; i < 256; i++) {
if (slovo[i] != slovo1[i]) {
match = false;
break;
}
}
if (match) {
printf("Polia sa zhoduju\n");
} else {
printf("Polia sa nezhoduju\n");
}
na to existuje v string.h uzasna funkce strcmp...
if(strcmp(retezec1, retezec2) == 0){
cout << "Retezce jsou stejne";
} else if(strcmp(retezec1, retezec2) < 0){
cout << "Retezec c. 1 je trosicku bliz k zacatku abecedy..";
}
To sn3d: ja mam zase pocit, ze napsal "ve kterem je nejake slovo"..
A pokud preci jen slo o porovnani obecneho bloku pameti(pole), tak bych volil funkci memcmphttp://cplusplus.com/reference/clibrary/cstring/memcmp.html.
To lol:
{
char slovo[256];
char slovo1[256];
char *s1 = slovo;
char *s2 = slovo1;
for(; (s1)&&(s2)&&(s1 == s2); ++s1, ++s2)
if (s1 == s2); //nebo libovolne porovnani -- jsou-li stejne vrati true, jinak false --tedy pak se provede akce
akce();
}

Přidej příspěvek
Toto téma je starší jak čtvrt roku – přidej svůj příspěvek jen tehdy, máš-li k tématu opravdu co říct!
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
Aktuálně jsou podporována videa ze serverů YouTube, Vimeo a Dailymotion.
×






























































Uživatelé prohlížející si toto vlákno
Uživatelé on-line: 0 registrovaných, 179 hostů
Podobná vlákna
Porovnání dvou řetězců v poli — založil avalagne
Porovnání dvou datumů — založil TomasUL
Porovnání dvou tabulek — založil WeeHool
Porovnani dvou stringu — založil insider
Porovnání dvou řetězců — založil jouda
Moderátoři diskuze