Hey there~ Im looking for a way to break a string into substrings without the use of strtok()...I wrote my own function but i think there are some bugs in it but i just cant seem to find out the problem...Hope you all will help me out here...Thanks in advance for the help!!
Code:#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> int main() { char string[50]; char words[60][60]; int wordNum = 0; int charNum; int length, i, j; fgets(string,sizeof(words),stdin); length = strlen(string); for(i = 0; i < length; i++) { charNum = 0; if(!isspace(string[i])) { words[wordNum][charNum] = string[i]; charNum++; } else { wordNum++; } } printf("\n\n"); for(i = 0; i <= wordNum; i++) { for(j = 0; words[i][j] != '\0'; j++) { if(isalnum(words[i][j])) printf("%c",words[i][j]); } printf("\n\n"); } return 1; }



LinkBack URL
About LinkBacks


