-
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]);
}
-
that's because bconf[i] is a single char, strcat expects a string of chars.
-
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';
}
-
I'd suggest to use sprintf instead of itoa, since itoa isn't ANSI
-
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
-
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);
-
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);
-
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;
-
Thanks, This should keep me busy for awhile.