Frage zu Suchfunktion.
-
Hi Leute,
ich brauche euere Hilfe.
Ich habe ein Array, der so aussieht:
Array[8]={ 1, 1, 1, 2, 2, 3, 3, 3 };
1,1,1,2,2... sind pids.
Ich habe z. B.
pid =1;
while (k !=5) { for ( i =0; i < 7; i++) { if ( pid == Array[i]) { index = i; test = 1; break; } else { continue; test =0; } } if ( test ==0) { printf ("habe nichts gefunden") }else{ printf ("Index %d\n", index); } k++; }
Frage: Ich möchte dass der Algorithmus
Pid=1
findet, und gibt
Array[0], Array[1], Array[2]
und nicht immer
Array[0]
aus.
Vielen Dank im Voraus?
Lena
-
ungefähr so
... for (i=0; i<sizeof(Array)/sizeof(int); i++) if (Array[i] == pid) printf ("Index %d\n", i); ...
-
} else { continue; test =0; }
"test = 0" is never executed!