I want to exchange pointer values, but it doesn't work and I'm stumbled
I would be grateful if you could give me a recommended reference book that describes how to use the pointer
It would be helpful if you could give me advice on the code
code
#include<stdio.h>
int input_int (int * pd);
void swap_int (int * pdata1, int * pdata2);
int main (void)
{
int data1, data2;
while (input_int (&data1)! = EOF&&input_int (&data2)! = EOF) {
printf ("** Before exchange ** \ n");
printf ("data1 =% d \ n", data1);
printf ("data2 =% d \ n", data2);
swap_int (&data1,&data2);
printf ("** After exchange ** \ n");
printf ("data1 =% d \ n", data1);
printf ("data2 =% d \ n", data2);
printf ("\ n");
}
return 0;
}
void swap_int (int * pdata1, int * pdata2)
{
int tmp;
tmp = * pdata1;
* pdata1 = * pdata2;
* pdata2 = tmp;
printf ("Input num:");
return scanf ("% d% d",&* pdata1,&* pdata2);
}
Error details
swpint.c: In function 'swap_int':
swapint.c: 48: 10: warning: 'return'with a value.in function returning void
return scanf ("% d% d",&* pdata1,&* pdata2);
swapint.c38: 6note: declared here
void swap int (int * pdata, int * pdata2)
Is the error message
The execution image is
input num: 10
input num: 20
** Before replacement **
data1 = 10
data2 = 20
** After exchange **
data1 = 20
data2 = 10
Execution image when it can be executed
-
Answer # 1
-
Answer # 2
Warning is a function that does not return a value (that is, void), but it is trying to return a value.
・ Stop return
・ A function that is not void
Either.But before, the questioner himself probably doesn't understand the swaip_int () function.
If you stop
What kind of input (it is an argument), what kind of processing is performed, what is returned (or nothing is returned),
Please organize.return and create input_int (), I think the expected behavior is for the time being.
Related articles
- string exchange using c language pointers
- c - approximate pi from integer grid points when radius is very large
- Python implements dictionary key and values exchange
- Range of Integer values in JAVA
- How C language uses XOR to exchange two values
- C ++ use XOR operation to exchange the values of two numbers
- Analysis of four methods to exchange values in Python
- maximum and minimum values of scanf function
- i want to find the k-th smallest integer that satisfies 1 * p1 ^ n * p2 ^ n * p3 ^ n (n> = 0) in c language
- scanf function integer
- i want to get numerical values in c
- count consecutive same values
- i want to be able to input the integer value n of this program by command argument
- c# - how to output integer values given letters and numbers from standard input
- python 3x - exchange of values between classes
- c - array shows all values entered so far
- program that sorts three values in ascending order
- i want to extract the latitude, longitude and zoom values from the google map url and output them
- i want to fix the matrix values to the correct result
- find the maximum, minimum, and average values in c language
* data1 = * data2;