Sunday, August 2, 2009

C problem When I'm deleting a string and print it. it doesnt prints blank it prints unknown characters.?

I want to print it blank and not unknown characters

C problem When I'm deleting a string and print it. it doesnt prints blank it prints unknown characters.?
How are you "deleting" the string? I'm a little rusty at C but if I recall correctly strings cant be changed or anything. You probably end up having a pointer to some weird memory address. I believe there is a better class for handling strings called BufferedString. Try using that class instead and see if you still have the weird character problem.
Reply:How are you deleting the string? I'm pretty sure it's doing this because the method you are using is erasing the variable array but not the memory location. It's either that or the string has been set to null.





The next question is, if you just want to cout or printf blank, why not just set the array to all spaces or something?
Reply:Three things come to mind:





1) You are printing something out that doesn't have any meaningful memory assigned to it. Off the top of my head:





int array[4], i;


for ( i = 0; i %26lt; 4; i++ ) {


array[i] = i;


}


printf("Something %d\n", array[4]);





What's happening here is that the array index 4 doesn't point to anything in particular, whatever happened to be lurking in memory there would get output.





2) You actually want to print out spaces:





printf(" ");





would actually print out a blank space.





3) You want to backspace over something that you've output before.





printf("\b");





will print a backspace character. This should "back up" over one character that you've previously printed.


No comments:

Post a Comment