Hey guys i have the following code just wondering how i can print a particular character in the pointer array. For eample 'w' or the second last 'd'?
Code:
char *worddude[] = {"dude!"};
printf("the value of word is %s",*worddude);
Printable View
Hey guys i have the following code just wondering how i can print a particular character in the pointer array. For eample 'w' or the second last 'd'?
Code:
char *worddude[] = {"dude!"};
printf("the value of word is %s",*worddude);
Well, you're not going to be able to print 'w' because it's just part of your variable name. Unless you open the executable file and look up the symbol table then you're limited to printing the characters in the string "dude!". You can print an individual character from it by printing worddude[0][whatever_char].
Code:printf("%c",*worddude[n]); //n is the place of the chararcter u want to print..considering the first to be at place n=0
Ah good old Ping. Close, but never correct...
Lose the *.Quote:
Originally Posted by PING
Quzah.
Actually, you need the *, but OOO is incorrect. *worddude[n] will print the first character of the nth string which is not what you want. The correct way is (*worddude)[n] which will print the nth character of the first string.Quote:
Originally Posted by quzah
D'oh. I wasn't seeing the * in the origional declaration for some reason.
Quzah.
Same here..thats y i had to edit my post..Quote:
D'oh. I wasn't seeing the * in the origional declaration for some reason.
yup, my bad, forgot to put those brackets..neways, m off to sleep now.Quote:
(*worddude)[n]