473,671 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

about atoi

sam
Hi, whats the meaning of atoi function here.
int atoi(char __ch)
{
switch(__ch)
{
case '0':return 0;
case '1':return 1;
case '2':return 2;
case '3':return 3;
case '4':return 4;
case '5':return 5;
case '6':return 6;
case '7':return 7;
case '8':return 8;
case '9':return 9;
};
return -1;
}

Jan 23 '07 #1
4 2456
sam wrote:
Hi, whats the meaning of atoi function here.
The meaning is the following:
int atoi(char __ch)
{
switch(__ch)
{
case '0':return 0;
case '1':return 1;
case '2':return 2;
case '3':return 3;
case '4':return 4;
case '5':return 5;
case '6':return 6;
case '7':return 7;
case '8':return 8;
case '9':return 9;
};
return -1;
}
(Can't you figure it out yourself?)

Regards,
Daniel
Jan 23 '07 #2
On 2007-01-23 18:04, sam wrote:
Hi, whats the meaning of atoi function here.
atoi is short for ascii to integer, it converts a char-string like "345"
to the integer 345. This however is someones attempt to implement that
function on their own and this version can only handle one-digit number.
There are better ways to do that, something like this (haven't tried):

int ator(char ch)
{
if (ch < '0' || ch '9')
return -1;
else
return ch - '0';
}

--
Erik Wikström
Jan 23 '07 #3
sam wrote:
Hi, whats the meaning of atoi function here.
int atoi(char __ch)
atoi() is a standard library function. It does not have the signature
given above. It should be:

int atoi(const char *nptr);

We'll assume it's some other function name and go from there.
{
switch(__ch)
Identifiers starting with __ are reserved for the implemenation.
{
case '0':return 0;
case '1':return 1;
case '2':return 2;
case '3':return 3;
case '4':return 4;
case '5':return 5;
case '6':return 6;
case '7':return 7;
case '8':return 8;
case '9':return 9;
};
This switch is rather pointless. You can do the same thing more simply
with:

if (ch < '0' || ch '9')
return -1;
else
return ch - '0';

Brian

Jan 24 '07 #4


On Jan 23, 10:04 pm, "sam" <samsoft...@yah oo.comwrote:
Hi, whats the meaning of atoi function here.

int atoi(char __ch)
{
switch(__ch)
{
case '0':return 0;
case '1':return 1;
case '2':return 2;
case '3':return 3;
case '4':return 4;
case '5':return 5;
case '6':return 6;
case '7':return 7;
case '8':return 8;
case '9':return 9;
};
return -1;
YOUR /Above written atoi takes one input character and return
appropriate integer or -1 as error.

1. Give it Good Name so it will not conflict.
2. Dont Provide input string, it is asking for Input char.
3. I think __varname is platform reserved variable, but i am not sure.
4. Is there need of this function cant you use atoi (widely used) ?
5. Why I am answering to this question ?
>

}- Hide quoted text -- Show quoted text -
Jan 25 '07 #5

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

Similar topics

19
7436
by: Mike Moum | last post by:
I think there may be a bug in string.atoi and string.atol. Here's some output from idle. > Python 2.3.4 (#2, Jan 5 2005, 08:24:51) > on linux2 > Type "copyright", "credits" or "license()" for more information. > > **************************************************************** > Personal firewall software may warn about the connection IDLE > makes to its subprocess using this computer's internal loopback
3
4152
by: Victor | last post by:
I'm trying to run this java program, but somehow the program always quit w/o giving any error msg at all. it happenned inside the first case statements. Strangely, after printing happen2, it just stopped, and I had no idea what happens. another error is on the last function. I have already declared plane as M x N array, but it keeps giving error like hwone.cpp(50) : warning C4101: 'plane' : unreferenced local variable hwone.cpp(212) :...
6
16044
by: John Smith | last post by:
What's wrong with the use of atoi in the following code? Why do I get the error message: 'atoi' : cannot convert parameter 1 from 'char' to 'const char *' char cBuffer; void PushUnique(int); for(y = 0; y < 9; y++)
5
36421
by: Bansidhar | last post by:
atoi() function seems not to have any support for Hex, octal number. Usually when I read from a text file then it contain number like 0x232 etc. In this case atoi() fells. In case of itoa() there is arrangement of passing the radix. Is there any historical reason that it is not the case with atoi() ? Is there any alternate function in C,C++ for atoi() to take care of all these things ? --Bansidhar
15
29205
by: puzzlecracker | last post by:
does anyone know how to implement this function efficiently?
9
4028
by: Would | last post by:
Hey, hopefully one of you can help me... I keep getting an unresolved external 'atoi(char)' and I dont know why.. here is the code #include <iostream> #include <stdlib.h> using namespace std; void main() { int atoi(char c);
3
4183
by: pauldepstein | last post by:
The following description of atoi is pasted from cplusplus.com. My question is after the pasting. ***** PASTING BEGINS HERE ****** int atoi ( const char * str ); <cstdlib> Convert string to integer Parses the C string str interpreting its content as an integral
11
4250
by: Nezhate | last post by:
Hi all, Can you help me? Why this warning appears in the next simple code ? warning: passing argument 1 of ‘atoi’ makes pointer from integer without a cast. #include <stdio.h> #include <stdlib.h> #include <string.h> int i;
50
5215
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 success or not. Am I wrong? Bill
0
8476
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8820
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8598
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7433
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5695
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4224
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2810
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2051
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.