Question

In C.

// Extract the integer from the input string and convert to int int convert(char *input){ // Declare int for result extracted

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>
#include <math.h>

int convert(char *input)
{
//variable declaration and initialization
int res = 0;
int i, j=0;
char num[10];
char ch;
int error=0;
int count=0;

for (i = 0; input[i] != '\0'; i++)
{
ch = input[i];
if(isdigit(input[i]))
{
num[j] = ch;
j++;
}
else
{
error++;
}
}
i=j;
for(j=0; j<i; j++)
{
res = res + (num[j]-48) * pow(10, i-j-1);
}
  
//return statement
return res;
}


int main()
{
//character array declaration
char input[] = "1247";
int num;

//function calling
num = convert(input);
printf("%d", num);
return 0;
}

OUTPUT:

1247

Add a comment
Know the answer?
Add Answer to:
In C. // Extract the integer from the input string and convert to int int convert(char...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT