473,396 Members | 1,833 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

arguments question

Hi, i have following problem:
when i tried to run following code, i`ve got segmentation fault
error
char s[255];
char d[1024];

char* ps = s;
char* pd = d;
size_t ss = sizeof(s);
size_t sd = ss;

if( -1 == iconv( des, ( char**)&s, &ss, (char**)&pd, &d ) )
....

and if i pass to iconv ps and pd instead of s and d, it`s all working
good.What is the difference???

sorry for my bad english:)
Jan 17 '08 #1
2 1183
pa********@gmail.com wrote:
Hi, i have following problem:
when i tried to run following code, i`ve got segmentation fault
error
char s[255];
char d[1024];

char* ps = s;
char* pd = d;
size_t ss = sizeof(s);
size_t sd = ss;

if( -1 == iconv( des, ( char**)&s, &ss, (char**)&pd, &d ) )
&s is not the address at which you will find the address of a character.

's' on its own is a pointer to char - a pointer to the first char in the
array.

'&s' is a pointer to array of char - a pointer to the whole array.
Jan 17 '08 #2
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
Jan 17 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Chuck Anderson | last post by:
I have a function with 7 inputs. The last three have default values. I want to call that function specifying the first four, skip two and then specify the last. I thought I could write this...
5
by: Eric Chong | last post by:
I created a Windows Service in C# that requires to get passed command arguments like a Console App. I noticed that there is an option "Start parameters" text box in the property of a Windows...
10
by: Agent Mulder | last post by:
Hi group, Almost 3 weeks ago I posted a short question here and in comp.std.c++ and I got exactly 1 respons, from Kevin Goodsell. He said he didn't want it. I post it here again, this time in a...
5
by: Adam | last post by:
Maybe this is a simple question, but what Arguments can be used with the familiar MM_swapImage? I can get it to work no problem, in this way: MM_swapImage('THE NAME OF OLD IMAGE...
12
by: Joel | last post by:
Hi all, Forgive me if I've expressed the subject line ill. What I'm trying to do is to call a c++ function given the following: a. A function name. This would be used to fetch a list of...
6
by: Melkor Ainur | last post by:
Hello, I'm attempting to build an interpreter for a pascal-like language. Currently, I don't generate any assembly. Instead, I just build an abstract syntax tree representing what I've parsed...
7
by: Li Pang | last post by:
Hi, I used thread to start a process which needs one or more arguments, my question is who to call the function from a thead? My codes are following: Private Sub myProcess(ByVal max as...
41
by: Telmo Costa | last post by:
Hi. I have the following code: -------------------------------------- function Tunnel() { //arguments(???); } function Sum() { var sum = 0; for (i=0; i<arguments.length; i++) sum +=...
36
by: Pacific Fox | last post by:
Hi all, haven't posted to this group before, but got an issue I can't work out... and hoping to get some help here ;-) I've got a base object that works fine with named arguments when called...
12
by: lorlarz | last post by:
In the code sample below, how are arguments a legitimate argument to Array.slice? Function.prototype.bind = function(){ var fn = this, args = Array.prototype.slice.call(arguments), object =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.