C language about using SSCANF to implement string addition and subtraction

Source: Internet
Author: User

#include <stdio.h>
#include <string.h>
void Main () {

int A;

int b;

Char str1[10] = "99999";
Char str2[10] = "1111111";
Char str[30];
int k = 0, i = 0, j = 0;
for (k = 0; k < 30&&i<strlen (str1);) {
str[k++] = str1[i++];
}
Str[k] = ' + ';
Str[++k] = 0;
strcat (str, str2);
SSCANF (str, "%d+%d", &a, &b);
printf ("%d\n", A + B);
}

The above program realizes the STR1 and str2 string addition and subtraction, why add ' + ' in the middle of STR, is to be able to construct a regular pattern in accordance with the "%d+%d" format in sscanf, the above is to use the regular type of sscanf to easily implement the string addition and subtraction

Boring yards a yard, a lot of fun

C language about using SSCANF to implement string addition and subtraction

Related Article

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.