473,382 Members | 1,302 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,382 software developers and data experts.

getting invalid atoi value for the below program

Hi,
getting invalid atoi value for the below program, help me resolving this issue.

Expand|Select|Wrap|Line Numbers
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <math.h>
  4.  
  5. int main () {
  6.     char *num = "222211113333";
  7.     int atNum ;
  8.     printf ("character value :%s\n ", num);
  9.     atNum = atoi (num);
  10.     printf ("\n\ninteger number : %d\n", atNum);
  11. }
Jan 16 '10 #1
2 2367
Banfa
9,065 Expert Mod 8TB
OK Please put code tags, [code] ... [/code] round your code.

Also give us all the information you say you are getting an invalid vale well what was the value you where getting? What was the value you where expecting?

I am guessing you where expecting the value 222211113333 to be output and you either got 3167781237 or 2222111133 but you will need to confirm that.

You need to ask yourself 2 questions:
  1. How many bits do I need to hold the value 22221111333? You should easily be able to answer this with the aid of the calculator on your computer.
  2. How many bits does an int hold on my platform? Something you should be able to answer by reading the platform documentation or looking in the header files (limits.h for example).
Jan 17 '10 #2
Ectara
24
Also consider whether or not your datatype is unsigned; it has an effect on the maximum size of your positive integer. That said, your string literal still contains a number larger than both signed and unsigned 32 bit integers can hold.
Jan 18 '10 #3

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

Similar topics

10
by: Vishal Grover | last post by:
Hello Everyone, I am seeing a certain behaviour which I find strange, and am curious to get an explanation to it. I have the following program. #include <iostream> #include <cstdlib> using...
5
by: James Gregory | last post by:
#include <cstdlib> #include <cctype> #include <string> template <class Input_Iter> inline int IterToInt(Input_Iter& iter, const Input_Iter& lineEnd) { char tempArray = {0}; for (int i = 0;...
6
by: Allan Bruce | last post by:
Hi there, I am loading in a 3d object from file. The code I have works fine but it is very slow for objects with many vertices, i.e. >5000 I make use of the atoi function 3 times for each vertex,...
15
by: Anonymousgoogledeja | last post by:
Hi all, since the function atof, atoi, _atoi64, atol returned value are Return Values Each function returns the double, int, __int64 or long value produced by interpreting the input...
5
by: ME | last post by:
What is the fastest way of getting the fraction part of a floating point number? So, if I have a float 10.3 I want to get a float with value 0.3 fast. Thanks
0
by: shrik | last post by:
I have following error : Total giant files in replay configuration file are : File name : /new_file/prob1.rec Given file /new_file/prob1.rec is successfully verified. Splitting for giant file...
4
by: toefraz | last post by:
Hey, guys. I'm writing a program that searches through a census file and returns a name for a inputted rank. I've been trying to get this function to parse the rank string to only get only the digits...
4
by: Ram | last post by:
Hi All, Firstly i am a newbie and trying to learn C. The background of the problem is Program: Presently I am working on a program of numerology and the I/P will be the name and output...
50
by: Bill Cunningham | last post by:
I have just read atoi() returns no errors. It returns an int though and the value of the int is supposed to be the value of the conversion. It seems to me that right there tells you if there was...
5
by: atulpatil09 | last post by:
when I am trying to compile the below code I am getting error as below, Could you please let me know how to solve the above compilation error for the below program snippet MList<MRvDispatcher...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...

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.