I am taking words and parsing them to put each in an array
but some how it tkes the word Hello and makes it hXe?l
What am I doing wrong, below is my code and the screen output. I think it has something to do with I don't know how to access values from and array or pointer?
-------------------screen output----------------
Test #0 hXe?l)lòo? num islam 5
theword= 32 t
----------
tqh?iBs? num islam 10
theword= 32 i
----------
i?s[ num islam 13
theword= 32 a
----------
aa num islam 15
theword= 32 t
----------
tde?s<t? num islam 20
theword= 0
----------
0 h
wPtr
1 ? t
wPtr
2 ? i
wPtr
3 [ a
wPtr ?
4 a t
wPtr ?
5 ?
wPtr ?
6 ² 4
wPtr
----------- end of screen putput ---------
TIA
DougP
< I Built one
but some how it tkes the word Hello and makes it hXe?l
What am I doing wrong, below is my code and the screen output. I think it has something to do with I don't know how to access values from and array or pointer?
Code:
int words_initialize( char* str, char* words[], int maxwords ){
int c; /* counter for for loop */
char n,m; /* holder for each letter */
char thewords[strlen(str)] ; /* array to hold first letter of each word */
char thewholeword[strlen(str)]; /* array to hold words*/
char *wPtr= &thewords[strlen(str)];
int counter = 1; /* counter to hold array index i.e. start of each word*/
int z; /* for printing array values as a double check */
/*printf("strlen %d\n",strlen(str)); */
/* get first letter to see if validacharacter and put in array*/
thewords[0]=str[0];
/* loop through each letter and examin it */
for (c = 0 ; c <= strlen(str) ; c++ ){
n=str[c];
printf("%c",n);
if (!isalnum(n)){
/*printf("num islam %d %c\n",c,n);*/
/* get start of each word and put into thewords array */
wPtr = &str[c+1]; /* set array of pointers*/
thewords[counter]=str[c+1]; /* since isalnum finds a non alpha/num
need to move forward one character which
is the start of the next word*/
printf("theword= %d %c\n",n, thewords[counter]);
/* change the character immediately following the
last character of each word so that it becomes a '\0'. */
/* thewholeword[counter] = '\0';*/
counter++; /* increment arraycounter for words and first letter*/
printf("----------\n");
}
else{
/* put the words in separate elements of thewholeword
re-build the whole word one letter at a time */
thewholeword[counter] =thewholeword[counter]+n;
printf("%c",thewholeword[counter]);
}
}
/* check out what we got */
for (z = 0 ; z <= counter ; z++ ){
printf("%d %c %c\n",z,thewholeword[z],thewords[z]);
printf("wPtr %c\n",wPtr[z]);
}
words[0] = &str[0];
return 1;
}
-------------------screen output----------------
Test #0 hXe?l)lòo? num islam 5
theword= 32 t
----------
tqh?iBs? num islam 10
theword= 32 i
----------
i?s[ num islam 13
theword= 32 a
----------
aa num islam 15
theword= 32 t
----------
tde?s<t? num islam 20
theword= 0
----------
0 h
wPtr
1 ? t
wPtr
2 ? i
wPtr
3 [ a
wPtr ?
4 a t
wPtr ?
5 ?
wPtr ?
6 ² 4
wPtr
----------- end of screen putput ---------
TIA
DougP
< I Built one