Thread: printing sorting pointer array

  1. #1
    Musicman - Canora
    Join Date
    Aug 2005
    Location
    Melbourne
    Posts
    252

    printing sorting pointer array

    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);

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    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].
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Nov 2004
    Location
    USA
    Posts
    516
    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
    Last edited by PING; 08-24-2005 at 09:14 AM.
    Code:
    >+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-] <.>+++++++++++[<++++++++>-]<-.--------.+++.------.--------.[-]>++++++++[<++++>- ]<+.[-]++++++++++.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Ah good old Ping. Close, but never correct...
    Quote Originally Posted by PING
    Code:
    printf("%c",*worddude[n]);
    Lose the *.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Quote Originally Posted by quzah
    Ah good old Ping. Close, but never correct...

    Lose the *.


    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.
    If you understand what you're doing, you're not learning anything.

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    D'oh. I wasn't seeing the * in the origional declaration for some reason.

    Quzah.
    Hope is the first step on the road to disappointment.

  7. #7
    Registered User
    Join Date
    Nov 2004
    Location
    USA
    Posts
    516
    D'oh. I wasn't seeing the * in the origional declaration for some reason.
    Same here..thats y i had to edit my post..
    (*worddude)[n]
    yup, my bad, forgot to put those brackets..neways, m off to sleep now.
    Code:
    >+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-] <.>+++++++++++[<++++++++>-]<-.--------.+++.------.--------.[-]>++++++++[<++++>- ]<+.[-]++++++++++.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why does C need pointer conversion
    By password636 in forum C Programming
    Replies: 2
    Last Post: 04-10-2009, 07:33 AM
  2. sorting using pointer to pointer not working
    By eager2no in forum C Programming
    Replies: 17
    Last Post: 09-21-2008, 12:52 AM
  3. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  4. Pointer with Multi-dimensional Array
    By whichet in forum C Programming
    Replies: 7
    Last Post: 11-28-2007, 12:26 AM
  5. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM