pa********@gmail.com wrote, On 17/01/08 14:58:
Hi, i have following problem:
when i tried to run following code, i`ve got segmentation fault
error
What follows is *not* a complete compilable example. Next time please
provide a complete compilable example since there may well be problems
in what you are not showing us.
char s[255];
char d[1024];
char* ps = s;
char* pd = d;
size_t ss = sizeof(s);
size_t sd = ss;
For example, we do not know if des in the line below has been correctly
set up.
if( -1 == iconv( des, ( char**)&s, &ss, (char**)&pd, &d ) )
For those who do not know the prototype for iconv (at least the one I
know about) is
size_t iconv(iconv_t, char**, size_t*, char**, size_t*);
and if i pass to iconv ps and pd instead of s and d, it`s all working
good.What is the difference???
Does "char s[255]" look line "char *ps"? What is the difference in
types? What happens if you remove the casts you added?
Note that adding casts because the compiler complains is almost always
the WRONG thing to do. In this case it stopped the compiler from telling
you that your code was wrong and did nothing to fix the problem.
Pointers are not arrays and arrays are not pointer. Go to
http://c-faq.com/ and read the comp.lang.c FAQ starting with section 6
where the first 10 questions are dealing with your mis-conceptions.
iconv is not actually topical in this group, although your problem is.
So it would be worth checking in comp.unix.programmer if you have other
questions about iconv rather than problems with the C language.
sorry for my bad english:)
Bad English is not a problem when you have done your best.
--
Flash Gordon