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

What is that continue statement??

4 Answers  


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

1 Answers   CSC,


Calculate 1*2*3*____*n using recursive function??

0 Answers  


When do you say that a digraph is acyclic A)if and only if its first search does not have back arcs B)a digraph is acyclic if and only if its first search does not have back vertices C)if and only if its first search does not have same dfnumber D)None of these

1 Answers   Accenture, IBM,


how to get starting address of a running C program

3 Answers  






1. main() { printf("%d",printf("HelloSoft")); } Output?

3 Answers   HCL,


What does d mean?

0 Answers  


Explain a file operation in C with an example.

0 Answers   Amdocs,


What was noalias and what ever happened to it?

0 Answers  


what is a pointer

4 Answers   Bank Of America, TCS,


write the program for maximum of the following numbers? 122,198,290,71,143,325,98

5 Answers  


Write a C program to fill a rectangle using window scrolling

1 Answers  


Categories