plz answer.. a program that takes a string e.g. "345" and
returns integer 345
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
What is that continue statement??
i=10,j=20 j=i,j?(i,j)?i:j:j print i,j
Calculate 1*2*3*____*n using recursive function??
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
how to get starting address of a running C program
1. main() { printf("%d",printf("HelloSoft")); } Output?
What does d mean?
Explain a file operation in C with an example.
What was noalias and what ever happened to it?
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
Write a C program to fill a rectangle using window scrolling