printing sorting pointer array

This is a discussion on printing sorting pointer array within the C Programming forums, part of the General Programming Boards category; Hey guys i have the following code just wondering how i can print a particular character in the 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,159
    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
    India
    Posts
    515
    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,159
    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
    India
    Posts
    515
    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-27-2007, 11:26 PM
  5. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21