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

I see that your function is empty. What have you tried so far?

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.

Basically, I am trying to copy the "message" to the "menu" and then display using the
*(menu+i) and *menu notation.

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

That helps a lot thanks a million.

That helps a lot thanks a million.

Make that million in small bills ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.