Thread: Char * problem

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    119

    Char * problem

    I have a char * array that holds strings at each index. My problem is the method that actually returns a char * to be stored in that array. Can anyone let me know how to do this in C.

    Code:
    char *array[MAX]
    
    //i basically want to format a string according to the parameters passed to the function
    char * store( int, int, char ch, int, int )
    {
         char row = { 8, 7, 6, 5, 4, 3, 2, 1 };
         char col = { a, b, c, d, e, f, g, h };
         char * string;
    
         //I want to do this, but I don't know how to in C, can I use the concatenate function?
         string = row[0] + col[0] + " " + ch + " " + row[4] + col[4];
         //string = 8a - 4e (would be the result of above )
         return string;
    }

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    You have to actually name the parameters in the function definition.

  3. #3
    Registered User
    Join Date
    Sep 2007
    Posts
    119
    I know, it was just a quick example to illustrate what i meant. Do you know of a solution to my string problem? I tryed using sprintf()

    sprintf( string, "parameters", variables )

    would this work?

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    sprintf() will work, however, string is just a pointer, and it's most likely not pointing to valid memory.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding info in a header file
    By hicpics in forum C Programming
    Replies: 8
    Last Post: 12-02-2005, 12:36 PM
  2. char problem
    By ForlornOdium in forum C++ Programming
    Replies: 10
    Last Post: 10-29-2003, 02:39 PM
  3. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM
  4. String Processing Problem
    By muffin in forum C Programming
    Replies: 0
    Last Post: 08-24-2001, 10:13 AM