Thread: A beginner passing strings

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    14

    A beginner passing strings

    I hope someone can help me, I am a beginner, and reading the posts here I am a bit out of my depth. I am trying to pass a string to a function, I have looked at other code examples and I cannot understand why it doesn't work, I am sure I am missing something really basic. Any help anyone could give me will be really appreciated:


    #include <stdio.h>


    #define SIZE 50


    void get_precision(char *s);


    int main(void)

    {

    /* Declare variable */


    char PROMPT_2[SIZE]= "Type a number from 1 to 10: ";



    get_precision(PROMPT_2);


    }

    get_precision(char *s)

    {

    printf ("%s", s);

    }

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    What errors do you get? I see that you've forgotten a void on the get_precision function definition.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Aug 2002
    Posts
    14
    Thanks Magos, I knew it would be something stupid, and when I remembered to put void in it worked. Thanks so much for your help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 04-29-2009, 10:13 AM
  2. Problems with strings as key in STL maps
    By all_names_taken in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 11:34 AM
  3. passing strings from functions as the "return" part
    By fraktal in forum C Programming
    Replies: 8
    Last Post: 12-13-2005, 01:38 AM
  4. Passing by reference not always the best
    By franziss in forum C++ Programming
    Replies: 3
    Last Post: 10-26-2005, 07:08 PM
  5. c-style string vs. c++-style strings
    By Mbrio in forum C++ Programming
    Replies: 3
    Last Post: 02-10-2002, 12:26 PM