•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 402,964 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 2,625 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: 641 | Replies: 6 | Solved
![]() |
•
•
Join Date: Oct 2007
Posts: 17
Reputation:
Rep Power: 1
Solved Threads: 0
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]
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;
}•
•
Join Date: Oct 2007
Posts: 17
Reputation:
Rep Power: 1
Solved Threads: 0
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;
}•
•
•
•
Basically, I am trying to copy the "message" to the "menu" and then display using the
*(menu+i) and *menu notation.
C Syntax (Toggle Plain Text)
#include <stdio.h> #include <string.h> void restaurant(char*); void restaurante( char *menu, int size ); int main() { char message[17] = { 'W', 'h', 'a', 't', 's', ' ', 'f', 'o', 'r', ' ', 'l', 'u', 'n', 'c', 'h', '?', '\0' }; int i, *mPtr; restaurant(message); putchar( '\n' ); restaurante( message, strlen( message ) ); getchar(); return 0; } void restaurant(char* menu) { while ( *menu ) { printf( "%c", *menu ); ++menu; } } /* or */ void restaurante( char *menu, int size ) { int i; for ( i = 0; i < size + 1; i++ ) { printf( "%c", *( menu + i ) ); } }
"No man's life, liberty, or property is safe while the legislature is in session." ~ Mark Twain
"No man's life, liberty, or property is safe while the legislature is in session." ~ Mark Twain
![]() |
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Forms in Random access files (Visual Basic 4 / 5 / 6)
- Returning 2-dimensional array, how? (C)
- dynamic memory allocation (C++)
- bubble sort function w/ array (C++)
- Help! C program w/Pointer Notation to Convert Text (C)
- Memory allocation for typedef struct (C++)
- Change Out Your Pointer Scheme (Windows tips 'n' tweaks)
- hm.. wiered.. (C)
- struct error (!?) (C)
Other Threads in the C Forum
- Previous Thread: Sort strings in lexicographical order but not to use built-in string functions
- Next Thread: Solution to my lexicographical sorting problem



Linear Mode