Im using this double while loop. Im new to C.
int crawler; char *desired[100]; crawler = getchar(); while(crawler != EOF) { int i = 0; while((crawler != '\n') && (crawler != EOF)) { desired[i] = crawler; i++; crawler = getchar(); } printf("%s", desired); } I just dont see why Im getting infinite loop in here (LLLLLLLLL..). Stdin looks like this:
Lorem(newline) Ipsum(newline) Beach(newline) Crocodile(newline) Crox(newline) C(EOF) Any idea? thanks.
char *desired[100];->char desired[100];. Also turn on compiler warnings (gcc -Wall ...) and pay attention to them !printf("%s", desired);<- you can't guaranteedesiredis a string here, it probably doesn't contain a terminating\0byte! 2.) your inner loop will happily overflowdesired, add a check!charstrings in C are really called null-terminated byte strings. That null-terminator Is important to not forget.