Afficher un message
Vieux 30/05/2008, 10h25   #15
CBFalconer
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Seg fault + string manipulation

Joachim Schmitz wrote:
> CBFalconer wrote:
>> Chad wrote:
>>>

>> ... snip ...
>>>
>>> Maybe I'm not thinking this through enough, but I REALLY don't
>>> see the difference between
>>>

>> ... snip ...
>>>
>>> Versus something like
>>>
>>> #include <stdio.h>
>>> int main (void) {
>>> char str[] = "Aamit";
>>> *str='R';
>>> puts(str);
>>> return 0;
>>> }

>>
>> The difference is between:
>>
>> char *str = "Aamit"; /* 1 */
>> and
>> char str[] = "Aamit"; /* 2 */
>>
>> in /* 1 */ str is a char pointer to a non-modifiable string. In /*
>> 2 */ str is a fully modifiable 6 char array, holding "Aamit\0".

>
> Read again. Chad was using char str[] in both cases, his only
> difference was printf vs. puts


That was in his last manual copy of the original problem. The

char* = "constant";

was the actual problem.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.


** Posted from http://www.teranews.com **
  Réponse avec citation
 
Page generated in 0,07853 seconds with 9 queries