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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the explanation for the dangling pointer in c?

688


Define recursion in c.

711


What is the meaning of ?

638


Is there any demerits of using pointer?

641


Explain what is a stream?

617






Can a function be forced to be inline? Also, give a comparison between inline function and the C macro?

665


What is character set?

690


What is the purpose of 'register' keyword?

705


How can I write data files which can be read on other machines with different word size, byte order, or floating point formats?

622


What are multidimensional arrays?

662


is it possible to create your own header files?

652


What is the use of a conditional inclusion statement in C?

613


How do I use strcmp?

651


Who invented b language?

928


What are multibyte characters?

655