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

State two uses of pointers in C?

642


what are the advanced features of functions a) function declaration and prototypes b) calling functions by value or by reference c) recursion d) all the above

682


4-Take two sets of 5 numbers from user in two arrays. Sort array 1 in ascending and array 2 in descending order. Perform sorting by passing array to a function mySort(array, sortingOrder). Then multiply both the arrays returned from function, using metric multiplication technique in main. Print result in metric format.

1731


Explain built-in function?

598


Can the sizeof operator be used to tell the size of an array passed to a function?

623






What is stack in c?

619


Explain what is #line used for?

610


What is void main () in c?

738


What is switch in c?

652


How many header files are in c?

559


how to capitalise first letter of each word in a given string?

1436


How do we print only part of a string in c?

592


What is the difference between c and python?

588


write a program to generate address labels using structures?

4012


we called a function and passed something do it we have always passed the "values" of variables to the called function. such functions calles are called a) calls by reference b) calls by value c) calls by zero d) none of the above

642