#include<stdio.h>
#include<stdlib.h>
void south_east(int *lat, int *lon){ // lat and lon are the pointer variables which take addresses as input , int *lat = &latitude
*lat = *lat - 1 ; // Using the * operator to update the values at the address.
*lon = *lon + 1;
}
int main(int argc, char const *argv[]) {
int latitude;
int longitude;
scanf("Enter Latitude and Longitude %i\n %i\n", latitude, longitude);
south_east(&latitude,&longitude); // We pass the addresses so that the function above can easily modify them
printf("Move to [%i, %i]\n", latitude, longitude );
return 0;
}
ships.c: In function 'main':
ships.c:14:40: warning: format '%i' expects argument of type 'int *', but argument 2 has type 'int' [-Wformat=]
scanf("Enter Latitude and Longitude %i\n %i\n", latitude, longitude);
^
ships.c:14:45: warning: format '%i' expects argument of type 'int *', but argument 3 has type 'int' [-Wformat=]
scanf("Enter Latitude and Longitude %i\n %i\n", latitude, longitude);
^
ships.c:14:3: warning: 'longitude' is used uninitialized in this function [-Wuninitialized]
scanf("Enter Latitude and Longitude %i\n %i\n", latitude, longitude);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ships.c:14:3: warning: 'latitude' is used uninitialized in this function [-Wuninitialized]
What's wrong with this? When I hardcode the values of latitude and Longitude, I get the desired output but when I use scanf() to get inputs, it gives me warinings!
scanfwithout checking the return value. See this page for further information: A beginners' guide away from scanf()