Assigning character pointer to a character pointer array?

If you want word to be an array of strings, then it should be declared as.

Up vote 0 down vote favorite share g+ share fb share tw.

In this below code I wan to copy the string in 'pre' to array 'word' so that I can print the array 'word' later but it's showing NONPORTABLE CONVERSION error.. Tried doing it using strcpy() but it dint work. Any other way of doing it? I want to store the strings present in 'pre' into an array each time it's generated.. void print(char *pre,struct dic * root,int depth) { int i=0,flag=0,int j=0; char *word; for(;inodei) { predepth='a'+i; flag=1; print(pre,root->nodei,depth+1); predepth=0; } } if(flag == 0) { predepth=0; printf("\n%s\n",pre); //j is declared globally ***wordj=pre;*** //printf("\nWord%d=%s\n",j,wordj); } } Thank you.. c link|improve this question edited Aug 5 '10 at 18:32Paul R48.9k43288 asked Aug 5 '10 at 18:29Amit62.

If you want word to be an array of strings, then it should be declared as : char **word; //and allocated accordingly If you want word to just be a copy of pre, you should have something more like wordj = prej; // in a loop, but using strcpy or strncpy would be just as good...

If I understand the question right... Your NONPORTABLE CONVERSION error is because wordj=pre; is trying to assign a char* to a char. You didn't say what didn't work about your strcpy(), but I'm assuming, given the code shown, that you hadn't allocated any memory for char *word, and were trying to copy into NULL. Instead, word=(char*)malloc(strlen(pre)+1); if (word) strcpy(word,pre).

Ahh, I re-read (right after submitting) and saw the commented-out line at the bottom of your code. @Matthieu is right that static char **word; is what you want, with malloc()/realloc() as necessary for both the original array of strings, and for each string that you strcpy() into. Note that it should be static if you're building onto this array every time you call into the function (and if it's only needed within the function).

– Crwth Aug 5 '10 at 20:06.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions