Not exactly.
A char in C is an integer type 1 byte wide, just like int or short or what
have you.  So when you have a char variable (char foo), it's one of those 1
byte integers.  A char array is a block of memory that the code treats as a
series of chars.  When you have a char array variable (char *foo or char
foo[length]), the variable actually contains a pointer to the first char in
the char array.  Well usually the first char.
In this case, he was trying to call a function that requires a char pointer
using a char.
That is why the compiler gave a warning, like "warning: passing arg 1 of
`sprintf' makes pointer from integer without a cast".  Because it was forced
to convert the char to a pointer.
--Palrich.

----- Original Message ----- 
From: "Davion Kalhen" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Saturday, December 20, 2003 10:30 PM
Subject: RE: Confusing bug


>
>
> Contrary to popular belief. sprintf does not allocate memory for
variables.
> char's are arrays, each spot holds a letter, the last spot of the array is
> marked with \0. So char spell_buf; is an array with 1 spot. Your trying to
> strap a spell into it. You can either malloc it, or just change "char
> spell_buf;" to "char spell_buf[MSL];
>
> Davion
>
>
> >From: Cyhawk <[EMAIL PROTECTED]>
> >To: [email protected]
> >Subject: Confusing bug
> >Date: Sat, 20 Dec 2003 18:57:17 -0800
> >
> >Hey all, maybe someone can help me with this, this is part of my random
> >item gen, pills specificly..
> >
> >Anywho, its crashing with (cygwin)
> >Program received signal SIGSEGV, Segmentation fault.
> >0x610b7841 in memmove () from /usr/bin/cygwin1.dll
> >
> >and (in linux)
> >
> >Program received signal SIGSEGV, Segmentation fault.
> >0x400beabc in _IO_str_overflow () from /lib/i686/libc.so.6
> >
> >I am confused.. ive never seen this before..
> >
> >As far as i can tell, i dont know whats causing this. While writing this
> >email ;) i remembered somewhere else i saw something im trying to achive,
> >so i changed the
> >sprintf for the short descr to
> > sprintf (prefix_full, "a small pill of %s",
skill_table[spell_num].name);
> >and it causes the same problems.
> >
> >Any help would be appreciated.. (oye im bad at this ;)
> >
> >-Thri
> >
> >Code snip below
> >
> >
> >
> >
> >OBJ_DATA *
> >thri_rand_item_pill (OBJ_DATA * obj, int level)
> >{
> >   char prefix_full[MSL];
> >   int spell_num;
> >   char spell_buf;
> >   int find_spell = number_range(1, 2);
> >
> > switch (find_spell)
> > {
> > case 1:
> > spell_num = skill_lookup ("detect invis");
> > sprintf( spell_buf, "detect invis");
> > break;
> > case 2:
> > spell_num = skill_lookup ("detect hidden");
> > sprintf( spell_buf, "detect hidden");
> > break;
> > }
> > obj = create_object (get_obj_index (30230), 0);
> > obj->value[0] = level / 2;
> > obj->value[1] = spell_num;
> >
> > sprintf (prefix_full, "a small pill of %s", spell_buf);
> > obj->short_descr = str_dup (prefix_full);
> > return(obj);
> >}
> >
> >
> >--
> >ROM mailing list
> >[email protected]
> >http://www.rom.org/cgi-bin/mailman/listinfo/rom
>
> _________________________________________________________________
> The new MSN 8: smart spam protection and 2 months FREE*
> http://join.msn.com/?page=features/junkmail
>
http://join.msn.com/?page=dept/bcomm&pgmarket=en-ca&RU=http%3a%2f%2fjoin.msn.com%2f%3fpage%3dmisc%2fspecialoffers%26pgmarket%3den-ca
>
>
> -- 
> ROM mailing list
> [email protected]
> http://www.rom.org/cgi-bin/mailman/listinfo/rom


Reply via email to