Re: reassigning value of a pointer
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Wed, 28 Sep 2005 22:49:56 GMT
bhalicki@xxxxxxxxxxx writes:
> hemalatha.gopalakrishnan@xxxxxxxxx wrote:
>> in the above program what is "c", not declared in the program, first u
>> declare that and assign a value and then print it ok. i think that
>> there is no problem in the line *s='a';
>> so try it and send me the result.
>
> Sorry, my apologies, *c should have read *s. I still can't figure this
> one. As far as I understand, *s is a pointer, which should point to a
> memory location which currently holds the value 't' (first character in
> string 'testing'). Without moving the pointer, I try to reassign this
> to the value 'a', but it seg. faults. I have even tried allocating
> memory with malloc/memset, but still the same result.
>
> I didn't want to use an array as I wanted to dynamically allocate
> memory based on string size (at runtime). I'm sure this has been done
> before without arrays and it seems logical.
I don't understand. Just yesterday, you wrote:
] Thanks for that information Walter. I managed to get it working, by
] allocating the memory then using strcpy to load the string.
Your original code had several problems. It declared a function
called "rename", which conflicts with the standard function of that
name. It attempted to modify a string literal (a segmentation fault
is a likely symptom in that case). And it used the name "c" rather
than "s", implying that the code you posted wasn't the actual code you
had tried.
If you're still having problems after fixing all these issues, try
posting your code again. Copy-and-paste the *exact* code that you fed
to the compiler; if you re-enter it manually, we won't be able to
guess which errors are in the original code and which are new typos.
--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
.
- References:
- reassigning value of a pointer
- From: bhalicki
- Re: reassigning value of a pointer
- From: bhalicki
- reassigning value of a pointer
- Prev by Date: Re: How do I check for directory existence in Linux?
- Next by Date: Re: How do I check for directory existence in Linux?
- Previous by thread: Re: reassigning value of a pointer
- Next by thread: Re: reassigning value of a pointer
- Index(es):
Relevant Pages
|
|