Re: [of topic] programming problems...

From: Michele Andreoli (m.andreoli@tin.it)
Date: Wed Jan 16 2002 - 19:32:35 CET


On Wed, Jan 16, 2002 at 07:36:14PM +0200, Vesa-Pekka Palmu nicely wrote:

> the code that is causing the problem is (in sort form) something
> like this:
>
> void main (void)
> {
> char variable[25];
> variable="string";
> }
>
> I have used all my little knowledge of programming on this one, but
> the problem remains and my hair is getting shorter :(
>
>

This code cannot work. You have these chances:

1)
        static char variable[25]="string";

2)
        char variable[25];
        strcpy(variable,"string");

3)
        char *variable="string";

When you define "char variable[25]", the C language simply create
a constant pointer called "variable" to a 25-byte area.
With the instruction :
                variable="string"

you didn't load a content in the area; you simply tried to change
the constant pointer!

This is the wonderfull world of C :-)

Michele

-- 
I keep trying to locate a meeting of Quantum Physicists. But everytime
they set a meeting time, the location changes. And vice versa -- Anonymous
---------------------------------------------------------------------
To unsubscribe, e-mail: mulinux-unsubscribe@sunsite.dk
For additional commands, e-mail: mulinux-help@sunsite.dk


This archive was generated by hypermail 2.1.6 : Sat Feb 08 2003 - 15:27:21 CET