Re: reassigning value of a pointer



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.
.



Relevant Pages

  • Re: Fast string operations
    ... Looping: I thought looping over arrays in managed code was "slow" ... array handling and such. ... The problem with TrimHelper is that it always returns a new string instance. ... The customer perceives this as a memory leak. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Discovering variable types...
    ... >- but I suppose MS expect us to use wrappers ... memory allocations for your variables from disk as well. ... >They most certainly are of fixed size, changing the size of a String ... >>me to keep buffer size and current postion right in the memory block. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Optimize
    ... if you use it like me to get 'the next string ptr' in addition. ... | |mov ebx eax;dw aligned strings are faster ... | Would it be enough to touch each 16th bytes in the 64K memory area ... Cache-line size is fixed, my AMD got 64 bytes per line. ...
    (alt.lang.asm)
  • Memory Question
    ... I have wrote a helper to my program which monitors object count, memory utilization and a threshold of 10% to determine how many objects are sticking around and how many are being garbage collected. ... occured right before the original String count). ... def print_threshold_breakers hsh1, hsh2, threshold ... putsf 'Building mem usage', mem_usage ...
    (comp.lang.ruby)
  • Re: Theodore Adorno, a prophet of data systems design
    ... > memory leaks, overruns etc., and I can even prove this without knowing ... possible to design a language in which buffer overruns are impossible. ... C makes the allocation of fixed-size arrays possible because there are some ... design and implement your own string model. ...
    (comp.programming)