User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 456,565 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,581 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 797 | Replies: 6 | Solved
Reply
Join Date: Oct 2007
Posts: 17
Reputation: theteamdrunk is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
theteamdrunk theteamdrunk is offline Offline
Newbie Poster

pointer notation

  #1  
Oct 21st, 2007
I need help with this problem. I have written the code. The function main() stores the message in an array. What I need to figure out is how to have the function restaurant accept the message as an argument(which is named menu) and display the message using pointer notation *(menu+i) and also again with the *menu notation.
Should I use this or something similar ? ptr[0] = ptr[10]

#include <stdio.h>
#include <string.h>

int restaurant(char*);
int main() {

    char message[17] = { 'W', 'h', 'a', 't', 's', ' ', 'f', 'o', 'r',
            ' ', 'l', 'u', 'n', 'c', 'h', '?', '\0' };
    int i, *mPtr;

    restaurant(message);

    return 0;
}
int restaurant(char* menu) {
    
    return 0;
}
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Posts: 62
Reputation: Ptolemy is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 8
Ptolemy's Avatar
Ptolemy Ptolemy is offline Offline
Junior Poster in Training

Re: pointer notation

  #2  
Oct 21st, 2007
I see that your function is empty. What have you tried so far?
Reply With Quote  
Join Date: Oct 2007
Posts: 17
Reputation: theteamdrunk is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
theteamdrunk theteamdrunk is offline Offline
Newbie Poster

Re: pointer notation

  #3  
Oct 21st, 2007
this is what I have come up with so far, I dont think its working just yet though
int restaurant(char* menu)
{   
    int i;
    char strcpy(char menu[], char message[]);
    {
        int i = 0;
        while (menu[i] != '\0')
        {
           menu[i] = message[i];
            i++;
        }
        menu[i] = '\0';
        return menu;
    
}
Reply With Quote  
Join Date: Oct 2007
Posts: 17
Reputation: theteamdrunk is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
theteamdrunk theteamdrunk is offline Offline
Newbie Poster

Re: pointer notation

  #4  
Oct 21st, 2007
Basically, I am trying to copy the "message" to the "menu" and then display using the
*(menu+i) and *menu notation.
Reply With Quote  
Join Date: Dec 2006
Posts: 1,569
Reputation: Aia is a splendid one to behold Aia is a splendid one to behold Aia is a splendid one to behold Aia is a splendid one to behold Aia is a splendid one to behold Aia is a splendid one to behold Aia is a splendid one to behold 
Rep Power: 12
Solved Threads: 114
Aia's Avatar
Aia Aia is offline Offline
Posting Virtuoso

Re: pointer notation

  #5  
Oct 21st, 2007
Originally Posted by theteamdrunk View Post
Basically, I am trying to copy the "message" to the "menu" and then display using the
*(menu+i) and *menu notation.

  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. void restaurant(char*);
  5. void restaurante( char *menu, int size );
  6.  
  7. int main() {
  8.  
  9. char message[17] = { 'W', 'h', 'a', 't', 's', ' ', 'f', 'o', 'r',
  10. ' ', 'l', 'u', 'n', 'c', 'h', '?', '\0' };
  11. int i, *mPtr;
  12.  
  13. restaurant(message);
  14. putchar( '\n' );
  15. restaurante( message, strlen( message ) );
  16. getchar();
  17.  
  18. return 0;
  19. }
  20. void restaurant(char* menu) {
  21. while ( *menu )
  22. {
  23. printf( "%c", *menu );
  24. ++menu;
  25. }
  26. }
  27. /* or */
  28. void restaurante( char *menu, int size )
  29. {
  30. int i;
  31. for ( i = 0; i < size + 1; i++ )
  32. {
  33. printf( "%c", *( menu + i ) );
  34. }
  35. }
At the very moment that I find myself in the side of the mayority, I will know that I need to re-think my ideas. ~ In my book.
Reply With Quote  
Join Date: Oct 2007
Posts: 17
Reputation: theteamdrunk is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
theteamdrunk theteamdrunk is offline Offline
Newbie Poster

Re: pointer notation

  #6  
Oct 21st, 2007
That helps a lot thanks a million.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 5:54 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC