| RyuKnightly (10) | |||
|
hello i got a problem , error text on console . Linux debian 6.06 in virtual box , the IDE is codeblocks the pict [IMG]http://i.imgur.com/U2ZWc.png[/IMG] the pict when i`m using windows , IDE is codeblocks [IMG]http://i.imgur.com/xC6zF.jpg[/IMG]
| |||
|
|
|||
| AleaIactaEst (99) | ||||
I am getting this warning when i compile your source file:
As far as i know the problem is that "You are my dreams " is a unnamed string constant (i.e. there is no variable which you can use to access the string). I guess the memory that is needed to store the string constant is de-allocated right after line 11 in your code, which results in unpredictable behaviour of your program (depending on compiler).To solve this problem you can omit the char* d variable:
| ||||
|
|
||||
| halitciftcise (3) | ||||
|
Hi, i want to give an idea . you must use dynamic variable for "d" . Becaus you use this variable in this section which is strcpy(d,"You are my dreams ") program output. >
| ||||
|
|
||||
| Peter87 (3912) | |
|
@AleaIactaEst The string is not deallocated. It stays there for the whole run of the program. The warning you get is because he uses a non-const pointer to point to data that should not be modified. The correct thing to do is to make d a const char*.@halitciftcise He doesn't need to use dynamic allocation. If you want to use dynamic allocation you should at least allocate an array that is big enough to hold the string. Now you are only allocating a single char. @RyuKnightly I don't see why you would get that output. Are you sure you use the exact same code on both systems? | |
|
Last edited on
|
|
| RyuKnightly (10) | |
|
@peter87 that's same code on both systems ... @alea & @halit ....thanks . it's solve :D ..... i see .. in linux , there are a little different things | |
|
Last edited on
|
|
| halitciftcise (3) | |
| thank you to you:) | |
|
|
|
| TimErickson (1) | |
| frytr | |
|
|
|
| kbw (5520) | |
| I hope you didn't use halitciftcise's solution. It's corrupts the heap and is bad advice. Go with Peter87's advice. | |
|
|
|