Thread: Need Help on C2664 error

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    80

    Need Help on C2664 error

    I'm using VisualC++ 4.0.

    I'm having a hard time trying to write an array to a list.
    I get a "cannot convert parameter 2 from 'char' to 'const char *" error when I try to compile it.

    Here's the declaration of the array:

    Code:
    char    bconf[MAXBND+1];    /* Bond CONFormation: ' ',c,t,C,T,E,Z */
    Here's how I'm trying to put it in a list. The list gets passed to a different application later:

    Code:
              char CFbconf[1000];//bconf[MAXBND + 1]
    
    
    
                for (i = 0 ; i <= MAXBND + 1 ; i++) {
    
                    if (strlen(CFbconf) > 1) {
                        strcat(CFbconf,",");    
                    }
                    
                    strcat(CFbconf,bconf[i]);
                
    
            
                }

  2. #2
    Unregistered User
    Join Date
    Sep 2005
    Location
    Antarctica
    Posts
    341
    that's because bconf[i] is a single char, strcat expects a string of chars.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    80
    Thanks, that gets me going in the right direction. I have been creating other lists like this, the difference is the other arrays are declared as integers. Here's what I've been doing and it seems to be working. Am I handling this wrong? Thanks again for helping me. You've helped me out many times.

    Code:
    			for (i = 0 ; i <= MAXATM + 1 ; i++) {
    
    				if (strlen(CFnaroma) > 1) {
    					strcat(CFnaroma,",");	
    				}	
    				
    				itoa (naroma[i],CFtemp,10);
    				strcat(CFnaroma,CFtemp);
    
    				CFtemp[0] = '\0';
    		
    			}

  4. #4
    Unregistered User
    Join Date
    Sep 2005
    Location
    Antarctica
    Posts
    341
    I'd suggest to use sprintf instead of itoa, since itoa isn't ANSI

  5. #5
    Registered User
    Join Date
    Aug 2005
    Posts
    80
    I tried using sprintf, but the resulting list ended up with a bunch of junk in it which I think was caused by padding:

    Code:
    sprintf(WarningList,"%s%d",WarningList,q[j]);
    should have produced the number 13

    instead had a bunch of symbols than the number 13

  6. #6
    Unregistered User
    Join Date
    Sep 2005
    Location
    Antarctica
    Posts
    341
    hmm, well, first, make sure that WarningList has been initialized and has a NULL terminator before calling sprintf, second you aren't supposed to use the same output as input, it has undefined behavior, so use another temporary char buffer:

    Code:
    char szTmp[32];
    szTmp[0] = 0;
    
    sprintf(szTmp, "%d", q[j]);
    strcat(WarningList, szTmp);

  7. #7
    Registered User
    Join Date
    Aug 2005
    Posts
    80
    Thanks, I'll give that a shot. I'm assuming that I should do that everywhere I'm dealing with charactors, instead of using strcat(), for example:

    Code:
    strcat(CFbconf,bconf[i]);
    to
    Code:
    sprintf(szTmp,"%s",conf[i]);
    
    strcat(CFbconf, szTmp);

  8. #8
    Unregistered User
    Join Date
    Sep 2005
    Location
    Antarctica
    Posts
    341
    well, if bconf[i] is a char, you would use %c, not %s in your sprintf.

    Or in that that it's a char, you could just do:
    Code:
    int n = strlen(CFbconf);
    CFbconf[n] = bconf[i];
    CFbconf[n+1] = 0;
    Last edited by rockytriton; 10-28-2005 at 12:35 PM.

  9. #9
    Registered User
    Join Date
    Aug 2005
    Posts
    80
    Thanks, This should keep me busy for awhile.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  3. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  4. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM