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 a nested formula?

607


What is p in text message?

541


When should a type cast be used?

576


How can I check whether a file exists? I want to warn the user if a requested input file is missing.

657


Explain goto?

718






When should a type cast not be used?

627


largest Of three Number using without if condition?

1009


Why is main function so important?

618


What are the types of unary operators?

663


What is the data segment that is followed by c?

616


A program is required to print your biographic information including: Names, gender, student Number, Cell Number, line of study and your residential address.

1253


Whats s or c mean?

594


How is pointer initialized in c?

587


What is the difference between exit() and _exit() function?

607


Write a program to reverse a given number in c language?

620