does anyone know why this doesnt work?
char BaseFileName[] = "soemthing%s";
char FileNameA[255];
sprintf(FileNameA,BaseFileName,"more");
sorry to do this, but i have to make this work by the end of the day... and i cant get it :(
Printable View
does anyone know why this doesnt work?
char BaseFileName[] = "soemthing%s";
char FileNameA[255];
sprintf(FileNameA,BaseFileName,"more");
sorry to do this, but i have to make this work by the end of the day... and i cant get it :(
I'd go for:
Code:char BaseFileName[] = "something";
char FileNameA[255] = {0};
sprintf (FileNameA, "%s%s", BaseFileName, "more");
Define "doesn't work". Are you sure it's not working? Did you print the string?
It doesn't? What doesn't work about it...?Quote:
does anyone know why this doesnt work?
It's a fairly simple line of code, and I'm not seeing anything wrong with it.
It compiles and seems to work correctly...
(You are aware you're using sprintf, and that sprintf() doesn't output anything to stdout?)
You must be doing something else wrong, because there is nothing obviously wrong with those 3 lines.
Try them in a 3 line program, and confirm it for yourself.
sorry.. by doesnt work i meant doesnt compile
Sorry i posted a silly quesiton like that on the board, but here is a good question
i found the problem .. but i dont understand why its happening.
I have noticed this many times before too.
If i put a command in the middle of my initialization of variables my program wont compile... why is that?
ie.
char face9[255];
face9="w00t";
int i;
//now my program would be broken
When you take the name of an array by itself, it's taken as a pointer to the first element, however it's considered const in the sense that you can't make it point to somewhere else. It can't be an lvalue in an expression (ie. nothing can be assigned to it).
Arrays can only be initialized during declaration.
ok.. well that was just me making a bad example.. sorry
lets use an easy one
int i,k;
i=9;
k=i*9;
short P;
//now my program doesnt work because i did operations before i finished all of my declarations.
oh.. ok problem solved.. thanks Cat guy