Avatar billede jens426 Nybegynder
23. februar 2007 - 09:28 Der er 7 kommentarer og
1 løsning

if problem

printf("\n");
printf(" 1: <b>%s</b> 2: <b>%s</b> ", ((struct entry*)(n->elm))->name, (char *)tok->elm);
printf("\n");   

if ((char *)tok->elm == ((struct entry*)(n->elm))->name) {
printf("fundet");
i = ((struct entry*)(n->elm))->value;
}

de første 4 linie kode genere følgende

1: <b>mus</b> 2: <b>test</b>
1: <b>test</b> 2: <b>test</b>

hvilket vil sige at if betingelse opfyldes, alt test==test. Hvorfor bliver printf("fundet"); aldrig aktiveret.

noget der har et løsningsforslag her
Avatar billede jpk Nybegynder
23. februar 2007 - 09:36 #1
== sammenligner referencerne, du vil sammenligne indholdet...
Brug fx strcmp:
http://www.cplusplus.com/reference/clibrary/cstring/strcmp.html
Avatar billede jens426 Nybegynder
23. februar 2007 - 09:58 #2
jeg skulle måske havde nævnt at jeg har så godt som null erfaring med c

har set på hjemmesiden, men compiler vil ikke acceptere det.

if strcmp ( ((struct entry*)(n->elm))->name,(char *)tok->elm)
{
printf("fundet");
}
Avatar billede jpk Nybegynder
23. februar 2007 - 10:04 #3
Hvilken fejl får du?

Har du inkluderet string.h?
Avatar billede jens426 Nybegynder
23. februar 2007 - 10:09 #4
ja
Avatar billede jens426 Nybegynder
23. februar 2007 - 10:11 #5
asm.c: In function `pass_two':
asm.c:312: parse error before `strcmp'
asm.c:331: parse error before `else'
asm.c: At top level:
asm.c:342: warning: passing arg 1 of `get_next' makes pointer from integer witho
ut a cast
asm.c:342: warning: initialization makes integer from pointer without a cast
asm.c:342: initializer element is not constant
asm.c:342: warning: data definition has no type or storage class
asm.c:343: parse error before `('
asm.c:348: redefinition of `tok'
asm.c:342: `tok' previously defined here
asm.c:348: warning: passing arg 1 of `get_next' makes pointer from integer witho
ut a cast
asm.c:348: warning: initialization makes integer from pointer without a cast
asm.c:348: initializer element is not constant
asm.c:348: warning: data definition has no type or storage class
asm.c:349: parse error before `('
asm.c:354: redefinition of `tok'
asm.c:348: `tok' previously defined here
asm.c:354: warning: passing arg 1 of `get_next' makes pointer from integer witho
ut a cast
asm.c:354: warning: initialization makes integer from pointer without a cast
asm.c:354: initializer element is not constant
asm.c:354: warning: data definition has no type or storage class
asm.c:355: parse error before `('
asm.c:360: redefinition of `tok'
asm.c:354: `tok' previously defined here
asm.c:360: warning: passing arg 1 of `get_next' makes pointer from integer witho
ut a cast
asm.c:360: warning: initialization makes integer from pointer without a cast
asm.c:360: initializer element is not constant
asm.c:360: warning: data definition has no type or storage class
asm.c:361: parse error before `('
asm.c:362: redefinition of `tok'
asm.c:360: `tok' previously defined here
asm.c:362: warning: passing arg 1 of `get_next' makes pointer from integer witho
ut a cast
asm.c:362: warning: initialization makes integer from pointer without a cast
asm.c:362: initializer element is not constant
asm.c:362: warning: data definition has no type or storage class
asm.c:363: parse error before `('
asm.c:368: redefinition of `tok'
asm.c:362: `tok' previously defined here
asm.c:368: warning: passing arg 1 of `get_next' makes pointer from integer witho
ut a cast
asm.c:368: warning: initialization makes integer from pointer without a cast
asm.c:368: initializer element is not constant
asm.c:368: warning: data definition has no type or storage class
asm.c:369: parse error before `('
asm.c:382: redefinition of `tok'
asm.c:368: `tok' previously defined here
asm.c:382: warning: passing arg 1 of `get_next' makes pointer from integer witho
ut a cast
asm.c:382: warning: initialization makes integer from pointer without a cast
asm.c:382: initializer element is not constant
asm.c:382: warning: data definition has no type or storage class
asm.c:383: parse error before `('
asm.c:405: parse error before `1'
asm.c:405: conflicting types for `exit'
C:\gcc\bin\..\lib\gcc-lib\i386-mingw32\2.95.2\..\..\..\..\i386-mingw32\include\s
tdlib.h:280: previous declaration of `exit'
asm.c:405: warning: data definition has no type or storage class
asm.c:416: parse error before `1'
asm.c:416: warning: data definition has no type or storage class
asm.c:422: parse error before `1'
asm.c:422: warning: data definition has no type or storage class
asm.c:426: redefinition of `tok'
asm.c:382: `tok' previously defined here
asm.c:426: invalid type argument of `->'
asm.c:426: warning: data definition has no type or storage class
asm.c:427: parse error before `}'
Avatar billede jens426 Nybegynder
23. februar 2007 - 10:23 #6
takker mange gange.

jeg fand en anden fution på den side du viste som kunne bruges.

strcoll

if (strcoll( ((struct entry*)(n->elm))->name,(char *)tok->elm) == 0) {printf("de næste 2 passer sammen");}

nu virker det
Avatar billede jpk Nybegynder
23. februar 2007 - 10:27 #7
Føj da...
Prøv evt. at vise noget mere af koden.
Avatar billede jpk Nybegynder
23. februar 2007 - 10:29 #8
Jeg havde ikke set dit sidste indlæg.
Det burde nu virke med strcmp...
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester