I'm a little late to the party here, I assume you've already got an answer from elsewhere.
But as it has had no replies - I will answer the question anyway.
The first thing I will say is:
"In future, please post ALL code inside code tags."
It will make your code easier to read because it will have syntax highlighting and all of the formatting/indentation of the code will be preserved. To put your code inside code tags, you can write this in your post:
[code=c]
// post your code here
[/code]
You can also use the 'insert' button on the post editors toolbar (the icon to the left of the "floppy-disk"/draft icon). Click insert, then select "code" and a dialog will pop up where you can post your code and you can specify the programming language used.
Your failure to use code tags makes your code look like it has more bugs than it actually does.
For example - These lines of code:
AND
C:
cese1[numdecece]=cadena3;
Are both appearing incorrectly in your post because you didn't use code tags.
So the line: "letradc=cadena3[i];" is appearing as "letradc=cadena3
;" because the array index "[i]" is being interpreted by
thecodingforums text editor as a tag for italics. Which is why the semicolon at the end of the line and all of the rest of your post is in italics.
And because of this - to anybody reading the code you posted, it looks as if you have a type-mismatch in those two assignment operations. Because the two types do not match.
e.g. letradc is declared as a char and cadena3 is an array of char.
Attempting to assign an entire array of char to a single char should result in a compiler error.
However - in the code you posted, I believe you are correctly using cadena3[i] and NOT cadena3 in those two assignments. So these bugs are just false-positives because you failed to use code-tags in your post.
Also, in this post - the reason that instances of [i]
are NOT being interpreted as italics tags is because I have enclosed them all in PLAIN tags.
So I'm guessing that the lines you pasted were originally:
and
C:
cese1[numdecece]=cadena3[i];
Which are both valid and correct assignments.
So ignoring all of the false-positives that were caused by your failure to use code tags in your post - the
REAL bug in your code is becuase the copied string "cese1" doesn't have a null terminator at the end of it, which is why you are getting the wrong size reported for it.
To fix the problem you need to add a null character '\0' to the end of the copied string in order to properly terminate it. You should do this immediately
AFTER the first for loop.
Also, you can refactor the logic of the first loop to completely remove the "letradc" variable, there is no point using a variable here. You can simply compare cadena3[i] against a space character.
So, applying the fix - your first for loop should look something like this:
C:
for(int i=0; i<tamanodc;++i)
{
if(cadena3[i]!=' ')
{
cese1[numdecece] = cadena3[i];
++numdecece;
}
}
// Append a null terminator character to the end of the copied string
cese1[numdecece]='\0';
Now your for loop will copy all of the non-space characters from cadena3 to cese1 and will correctly terminate the string. And you will get the correct output from your second for loop. So the final thing to do would be to implement some code to check whether or not the copied string is palindromic.
Again, for future reference - please post ALL code inside code tags!