473,399 Members | 2,278 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,399 software developers and data experts.

Wierd output with a command line argument

I'm curious to know if anyone can explain why the following code does not
return the second argument exactly, but rather appears to return a random
number (at least it does that on my box).

#include <stdio.h>

int main (int argc, char *argv[]) {
/* Make sure you enter a numerical second argument */
if (argc != 2)
return (0);
printf ("%f\n", atof(argv[1]));
return (0);
}

-Oscarian
Jan 10 '07 #1
2 1235

Oscarian wrote:
I'm curious to know if anyone can explain why the following code does not
return the second argument exactly, but rather appears to return a random
number (at least it does that on my box).

#include <stdio.h>

int main (int argc, char *argv[]) {
/* Make sure you enter a numerical second argument */
if (argc != 2)
return (0);
printf ("%f\n", atof(argv[1]));
return (0);
}
Include stdlib.h for supplying the prototype for atof, otherwise the
compiler assumes that it returns an int value.

Also consider using strtod which is bit more robust on bad arguments.

Jan 10 '07 #2
On Tue, 09 Jan 2007 23:47:33 -0800, santosh wrote:
Include stdlib.h for supplying the prototype for atof, otherwise the
compiler assumes that it returns an int value.
Thanks. That worked.

Cheers-
O

Jan 10 '07 #3

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

Similar topics

8
by: Joe | last post by:
I'm using Python 2.4 on Windows XP SP2. I'm trying to receive a command line argument that is a newline (\n) Here is the command line to use sample.py "\n" Here is a sample.py script
3
by: Bill Cohagan | last post by:
I'm writing a console app (in C#) and I want to be able to redirect the standard input/output streams when it's run at a command prompt. IOW I want to support the "<" and ">" redirection syntax....
2
by: SunRise | last post by:
Hi I am creating a C Program , to extract only-Printable-characters from a file ( any type of file) and display them. OS: Windows-XP Ple help me to fix the Errors & Warnings and explain...
6
by: tommaso.gastaldi | last post by:
Hi I am creating a pdf by just printing on Acrobat Distiller. This is fine. I need to create a pdf which has a given prespecified name and I do not wish that Distiller prompts me for a name....
51
by: Ojas | last post by:
Hi!, I just out of curiosity want to know how top detect the client side application under which the script is getting run. I mean to ask the how to know whether the script is running under...
0
by: jebbyleezer | last post by:
Hello, I have source code that builds correctly, however, after the program terminates the output file produced is empty. Here is my source code: import java.io.*; import java.util.Scanner;...
4
by: Tobiah | last post by:
I am not sure how to capture the output of a command using subprocess without creating a temp file. I was trying this: import StringIO import subprocess file = StringIO.StringIO() ...
7
by: Mark B | last post by:
How do I have a SiteMap based on the output of a stored procedure? (I want to pass a @LanguageCode parameter to it so it will display the top Menu in the appropriate language).
5
by: mlt | last post by:
How is it possible from main to supply MyErrorHandler wihtout arguments? void MyErrorHandler(CGcontext context, CGerror error, void *data) { char *progname = (char *)data; fprintf(stderr,...
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: 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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.