Hi people, i would be very thankful for ur help, maybe it takes a few minutes to understand the algorythm but if its possible take the time for it..
its about a c code and ive wroted the question directly into the code..
i dont understand where the problem is..Code:#include <stdio.h> #include <stdlib.h> #define ARR_MAX 8 int countLetters(char* string) { int counter; int letters = 0 ; for (counter = 0; string[counter] != '\0'; counter++) { letters++; } return letters; } int main() { char *text = "blablic,,.blablsub,blub,mi ma,maeh"; int array_position = 8; int array[array_position]; int length = countLetters(text); int text_counter; for(text_counter = 0, array_position = 0; text_counter < length; text_counter++) { if(text[text_counter] == ' ' || text[text_counter] == '\n' || text[text_counter] == '.' || text[text_counter] == ',') { array[array_position++] = text_counter + 1; } else array[array_position] = 0; } int array_counter; int position; char string_array[ARR_MAX][50] = { { 0 } }; int counter; int i; int break_up = 1; for ( position = 0, counter = 0, i = 0, array_counter = 1; counter < 50 && position < ARR_MAX; counter++, i++) { if ((text[i] == ',') || (text[i] == '.') || (text[i] == '\n') || (text[i] == ' ')) { if((array[array_counter] == (i+1)) && ((array[array_counter] - 1) == (array[array_counter - 1]))) { array_counter++; continue; //is that ok? because if yes, it should jump to the beginning of the for loop } else { string_array[position][counter] = 0; counter = -1; position++; } } else { string_array[position][counter] = text[i]; } } for (i = 0; i < ARR_MAX; i++) { if (string_array[i][0] == 0) break; printf("%s\n", string_array[i]); //why does it print only the first one? } return 0; }
thanx in advance



LinkBack URL
About LinkBacks




