I have this function and am trying to take a phrase such as
"hhh bb ww zzzzz" abd translate it. the Problem is I think on line strncat(newPhrase,s1,1);
even the program compiles without problems it won't run, it crashes.
How do I take whats passed in "phrase" and put it into a var so I can parse it?
DougP
"hhh bb ww zzzzz" abd translate it. the Problem is I think on line strncat(newPhrase,s1,1);
even the program compiles without problems it won't run, it crashes.
How do I take whats passed in "phrase" and put it into a var so I can parse it?
Code:
char* the_phrase(const char* const phrase){
/* See requirements for details on role and implementation
*/
/* intialize Vars */
int k;
char s1[] = "a";
char s2[100]; /* needed to make the strncat work */
char * newword;
char * newPhrase; /* var for final TTT Phrase */
for (k = 0; phrase[k] != '\0'; k++){
if(phrase[k] == ' '){
/*printf("%c\n Found a space");*/
/* add this new word to the newPhrase var */
strncat(newPhrase,s1,1);
}
else{
s2[k]=phrase[k];
/*printf("%c\n",s2[k]);*/
/* Build word one letter at a time */
}
}
return newPhrase;
}
DougP