"Write and call a function that displays instructions to the user"

This is a discussion on "Write and call a function that displays instructions to the user" within the C Programming forums, part of the General Programming Boards category; I'm a little bit confused. Usually a function looks like this I'm little bit confused so a function usually looks ...

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    140

    "Write and call a function that displays instructions to the user"

    I'm a little bit confused. Usually a function looks like this

    I'm little bit confused so a function usually looks like this right?

    name (int x,int y);

    How can i make it so that the function displays instructions?
    name (printf); ?


    where printf contains the instructions?

  2. #2
    Registered User
    Join Date
    Aug 2012
    Location
    Lagos, Nigeria
    Posts
    17
    What you can do is declare a function and make it accept a character array and output the array. Then call the function and pass a pointer to an initialised character array to the function.

  3. #3
    Registered User
    Join Date
    Oct 2012
    Posts
    140
    hmm so i did this in the prototype

    void instructions(void);

    Now how would i "call" the function in main?

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    2,372
    I appears that you're just supposed to put a "print" statement within a function (that you're to write yourself) and call that function from "main()". I'm sure you're over-thinking this assignment.

  5. #5
    Registered User
    Join Date
    Jun 2011
    Posts
    2,372
    Quote Originally Posted by tmac619619 View Post
    hmm so i did this in the prototype

    void instructions(void);

    Now how would i "call" the function in main?
    The same way you would call any function from "main()".

  6. #6
    Registered User
    Join Date
    Oct 2012
    Posts
    140
    Well the assignment is pretty simple. Input output. With a little bit of calculations.

    But its just that the "Write and call a function that displays instructions to the user is throwing me off"

    int main()

    curly bracket

    printf("instructions");

    curly bracket

  7. #7
    Registered User
    Join Date
    Aug 2012
    Location
    Lagos, Nigeria
    Posts
    17
    With the prototype u wrote, it means the function 'instruction' is not returning any value and it is not accepting any arguments. Since u want the function to display information, it must accept an argument. So, your prototype is wrong.
    Try something like this:

    Code:
       int main(void) {
        char name[] = "Hello World!";
        /*call the function*/
       instruction(name);
       }
    
      void instruction(char x[]) 
     {
        printf("%s",x);
     }

  8. #8
    Registered User
    Join Date
    Jun 2011
    Posts
    2,372
    The "print" statement has to be within a function. If you don't fully understand functions, you can read about them here.

    Or, to see a full [small] program that uses functions to add two numbers, refer to my post #4 here. Only, instead of adding and returning a value, you'll be printing instructions.

  9. #9
    Registered User
    Join Date
    Jun 2011
    Posts
    2,372
    @bluechip: It seems that the required function can print the information without any arguments, as arguments were not specified in the assignment. When I write a "menu" function, I don't pass information to it - all menu items are included in that function (though it does return the value selected by the user).

  10. #10
    Registered User
    Join Date
    Aug 2012
    Location
    Lagos, Nigeria
    Posts
    17
    @matticus: The function needs arguments, so that it will be able to print the content of any character array and as such any instruction

  11. #11
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    611
    You just need a function that prints instructions? Then you must realize that void is your best choice. You are not returning anything, therefore your return type is void. No arguments being passed so therfore you can use void there too. void foo(void); <---- Theres a nice start to a function.

  12. #12
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    @bluetooth: You are obviously a raw beginner. Do you really think it's appropriate for you to "answer" questions?

    If you read the OPs posts (and understand English) you will see that Matticus is correct.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. recursive function call to "_main"
    By Evade in forum C Programming
    Replies: 2
    Last Post: 11-02-2010, 01:23 PM
  2. Replies: 2
    Last Post: 02-27-2009, 11:46 AM
  3. Replies: 6
    Last Post: 06-14-2008, 08:08 AM
  4. "illegal call of non-static member function"
    By Hulag in forum C++ Programming
    Replies: 2
    Last Post: 04-12-2005, 07:44 AM
  5. Error: "illegal call of non-static member function"
    By Helix in forum Windows Programming
    Replies: 4
    Last Post: 12-31-2003, 09:01 PM

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