Thread: Please help me with a strcat() error

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    5

    Please help me with a strcat() error

    here is my main:

    int main(int argc, char* argv[])
    {
    char cA, cB;
    cA = 'A';
    cB = '\x6';
    cA = strcat(cA, cB);
    cout << cA;
    return 0;
    }

    I'm trying to add the cA and the cB character together...does anyone know what I'm going wrong, when I get the following error message?:

    cannot convert parameter 1 from 'char' to 'char *'

    I'm using Visual C++ 6.

    Thanks!

  2. #2
    Xterria
    Guest
    You can't do this because the type 'char' represents only one character. Which means if you put cA with the letter 'A' its ok but if you put it to 'AB' its not. To get around this you have to make your chars arrays. this is what you should have:


    Code:
    int main(int argc, char*argv[])
    {
          char cA[30];     //Notice that now you can put 30 chars in
          char cB[30];     //Ya can with this, too
    cA = 'A';
    cB = '\\x6';     //put the extra \ so that the compiler prints one
    strcat(cA, cB);  //You don't need cA =
    cout << cA;
    return (0);
    }
    /* This should print: 'A\x6' */
    I hope this helps you. If it doesn't just tell me

  3. #3
    >cannot convert parameter 1 from 'char' to 'char *'

    That would be your problem, yes. The error message tells you exactly whats wrong. cA needs to be of type "char *" (a pointer to a character string) not of type char. You need to declare your variables like this:

    char *cA, *cB;

    /* Edit */
    I see someone replied before i finished typing. One note: You only want that extra "\" if you want to display the next "\" instead of the escape sequence that i believe you intended here.

    Also: the cA[30] method is also acceptable for this but why declare room for 30 characters when you're only using 3 or so? Use a pointer and "new" to declare only as much space as you'll need.
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    5
    Actually, all I want to do is add the ASCII value 6 which is the Spade to a character, any Ideas?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 12:17 AM
  5. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM