I need scanf_s identifier

Asked 2 years ago, Updated 2 years ago, 50 views

#include <stdio.h>

void get_sum_diff(int x, int y, int* p_sum, int* p_diff);

int main(void)
{
    int x;
    int y;
    int r, s;

    printf("Enter an integer");
    scanf_s("%d %d", &x, &y); 

    void get_sum_diff(x, y, &r, &s);

    printf("sum of elements = %d", r);
    printf ("the difference between elements = %d", s);

    return 0;
}

void get_sum_diff(int x, int y, int* p_sum, int* p_diff)
{
    *p_sum = x + y;
    *p_diff = x - y;
}

It's a program that makes a function with a pointer as a parameter and gives the sum and the difference of the elements.

I tried to run the get_sum_diff function in the main function, but the &r and &s were red lines They need an identifier, where is it wrong?

c pointer visual-studio

2022-09-20 15:38

1 Answers

The problem did not occur in scanf_s, but the code below is the problem.

void get_sum_diff(x, y, &r, &s);

When using (calling) a function, it must be used without void as shown below. Note return values such as void only when declaring or defining a function; not when calling a function.

get_sum_diff(x, y, &r, &s);


2022-09-20 15:38

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.