cmd command line into DOS mode compile Run C language program implement string conversion

Source: Internet
Author: User

Requirement: Enter a string (less than 50 in length), then filter out all non-numeric characters, get a string of numeric characters and convert it to a double result output (4 decimal places).

SOURCE program:

#include <stdio.h>
int change (Char*source,char *des)
{
int i=0;
while (*source)
{
if (*source>= ' 0 ' &&*source<= ' 9 ')
Des[i++]=*source;
source++;
}
des[i]= ' + ';
return i;
}
Double Calcu (char*s)
{Double result=0;
while (*s)
{
result=result*10+ (*s-48);
s++;
}
return result;
}
int main ()
{
Char str[50],strdes[50];
Gets (str);
if (change (str,strdes))
{
printf ("%.4f\n", Calcu (Strdes));
}
Else
printf ("The digital string is empty!");
return 0;
}

Realize:

cmd command line into DOS mode compile Run C language program implement string conversion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.