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

Answers were Sorted based on User's Feedback



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

Answer / ramu

int f(char s[])
{
int num=0,i;
for(int i=0;s[i]>='0' && s[i]<='9';i++)
n=10*n+(s[i]-'0');
if(i<sizeof(s))
{
printf("Error String");
return 0;
}
return n;
{

Is This Answer Correct ?    5 Yes 0 No

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

Answer / swapnil chhajer

#include<stdio.h>
#include<stdlib.h>

int main()
{
char str[10];
printf("Enter the string : ");
gets(str);
printf("Converted integer : %d",atoi(str));
getchar();
}

Is This Answer Correct ?    5 Yes 0 No

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

Answer / 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

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

Answer / vignesh1988i

#include<stdio.h>
#include<conio.h>
#include<string.h>
int fun(char *,int);
void main()
{
long int c,l;
char a1[20];
printf("enter the numerical string :");
scanf("%s",&a1);
l=strlen(a1);
c=fun(a,l);
printf("\n%ld",l);
getch();
}
int fun(char *a,long int l1)
{
long int a1[]=
{1,10,100,1000,10000,100000,1000000,10000000,100000000},c;
int p=a1[l1-1],c=0;
for(int i=0;a[i]!='\0';i++)
{
y=((int)a[i])*p; /*TYPE CASTING*/
c=c+y;
p=p/10;
}
return c;
}

Is This Answer Correct ?    1 Yes 2 No

Post New Answer

More C Interview Questions

How can you find the day of the week given the date?

0 Answers  


formula to convert 2500mmh2o into m3/hr

0 Answers  


If I have a char * variable pointing to the name of a function ..

0 Answers  


Write a program to generate the first n terms in the series --- 2,3,5,7,11,...,17

0 Answers  


how can you print&scan anything using just one character? :) HINT: printf,scanf similer

2 Answers  


who did come first hen or agg

15 Answers   Infosys,


i=10,j=20 j=i,j?(i,j)?i:j:j print i,j

1 Answers   CSC,


write a c program to find biggest of 3 number without relational operator?

12 Answers   TCS, Wipro,


what r callback function?

1 Answers  


which one is better structure or union?(other than the space occupied )

2 Answers  


There is a 100-story building and you are given two eggs. The eggs (and the building) have an interesting property that if you throw the egg from a floor number less than X, it will not break. And it will always brake if the floor number is equal or greater than X. Assuming that you can reuse the eggs which didn't broke; you got to find X in a minimal number of throws. Give an algorithm to find X in minimal number of throws.

5 Answers   Yahoo,


hi send me sample aptitude papers of cts?

0 Answers  


Categories