468,512 Members | 1,398 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

Reading unsigned int from command line

From the command line, I passed a value like this:

a.out -seed 3333333333

But when I did:
unsigned int seed;

seed = atoi(argv[2]);

cout << seed;

it just puts out the decimal equivalent of 0x7fffffff; I cannot change the internal variable to int. Any hints?
Sep 13 '06 #1
2 3597
risby
30
From the command line, I passed a value like this:

a.out -seed 3333333333

But when I did:
unsigned int seed;

seed = atoi(argv[2]);

cout << seed;

it just puts out the decimal equivalent of 0x7fffffff; I cannot change the internal variable to int. Any hints?
Use strtoul() rather than atoi().

#include <stdlib.h>
unsigned long strtoul(const char *nptr, char **endptr, int base);
Sep 14 '06 #2
Banfa
9,056 Expert Mod 8TB
The actual problem is that atoi returns int even though you are assigning the value to unsigned and 3333333333 is outside the range of an int so it has returned INT_MAX = 0x7FFFFFFF
Sep 14 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by Santah | last post: by
8 posts views Thread by Phil Slater | last post: by
3 posts views Thread by Max | last post: by
20 posts views Thread by sahukar praveen | last post: by
7 posts views Thread by bhanuprakash | last post: by
21 posts views Thread by EdUarDo | last post: by
13 posts views Thread by anant | last post: by
21 posts views Thread by Stephen.Schoenberger | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.