plz answer.. a program that takes a string e.g. "345" and
returns integer 345

Answer Posted / vadivel t

The equalent code to atoi() library fuction which i hav
written, below.


#include<stdio.h>
#include<conio.h>

int MyAtoi(char *cptr);

main()
{
char *cptr = "123445";

printf("INTEGER EQU IS: %d\n", MyAtoi(cptr));
getch();
}
int MyAtoi(char *cptr)
{
int iptr = 0;
while((*cptr != '\0') && ((*cptr >= 48 && *cptr <= 57) ||
(*cptr == 32)))
{
if(*cptr != ' ')
iptr = (iptr * 10) + (*cptr - 48);
cptr++;
}
return iptr;
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

When can you use a pointer with a function?

571


What is the difference between struct and union in C?

575


What is the difference between a string and an array?

708


Can we replace the struct function in tree syntax with a union?

783


which is an algorithm for sorting in a growing Lexicographic order

1398






Can 'this' pointer by used in the constructor?

615


How many levels of indirection in pointers can you have in a single declaration?

596


to find the closest pair

1824


Why do we use return in c?

570


What language is windows 1.0 written?

575


What does c mean in basketball?

563


What is the time and space complexities of merge sort and when is it preferred over quick sort?

676


What is quick sort in c?

586


What is a volatile keyword in c?

638


What is bin sh c?

584