problem with atof

This is a discussion on problem with atof within the C Programming forums, part of the General Programming Boards category; hello guys,
i was with one of the problem where i was forced to use atof function. the problem here ...

problem with atof

hello guys,
i was with one of the problem where i was forced to use atof function. the problem here is, it returns me 0.0 always which mean there in an error while converting it. can any on tell me at what instance will the atof generator error. here is the peice of code where i used the atof function

>converted[ctr-1]=atof(*argv[ctr]);
And this is broken. argv[argc] is a null pointer, and because your loop continues through ctr having a value of argc, you're dereferencing a null pointer. Dereferencing argv[ctr] is also incorrect as it's already a pointer to char and that's what atof expects. Perhaps something more like this is what you want:

or when i use atoi rather than atof i will work fine by returning th proper interger value
but when i use the atof fucntion i returns me the 0.0 which is effectivly an error. and couldn't able to find the why it is an error

Gotta love the "please fix this for me, but I'm not going to tell you which functions we're allowed to use" posts.
It's like teaching people to walk by first breaking their legs - muppet teachers! - Salem

If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

Because your compiler feels like it. Or doesn't, as the case may be. There is nothing in regards to C which says how your compiler has to work as far as being nice enough to correct you when you do something silly like leave out headers.

What it should do is give you error messages saying it can't find the function you're trying to use. If it does work, well, you're lucky. If not, you end up with something like this. I suspect you were getting some warnings that you were ignoring.