TennisPrez12 Posted March 27, 2012 Posted March 27, 2012 Hi guys, I'm writing a simple program which takes similar values from a user at the keyboard. But I've run into some issues and I'm not sure why. It MUST be to do with the conversion specifiers but I just can't figure it out :/ Here's the code: /* * File: main.c * Author: daniel * * Created on March 27, 2012, 6:49 PM */ #include <stdio.h> #include <stdlib.h> #include "main.h" #define MAX_LAT 52.75 #define MIN_LAT 51.5 #define MAX_LNG 6.5 #define MIN_LNG 4.75 #define REQ_LAT 0.1 #define REQ_LNG 0.2 /* * This function takes a location value from the user and if any ships are * within 0.1 latitude or 0.2 longitude of this position the function will produce * a message and log the information appropriately */ int main(int argc, char** argv) { ship s; // struct in the headerfile containing latitude and longitude of type double double user_lat; double user_lng; // THESE TOP TWO PRINTFS WILL BE REPLACED BY VALUES TAKEN FROM OUR // DATA ENTRY PROGRAM printf("Please enter a specific latitude value for the vessel: "); scanf("%lf", s.latitude); printf("%lf", s.latitude); //used for de-bugging printf("Please enter a specific longitude value for the vessel: "); scanf("%lf", s.longitude); printf("Now enter a latitude area you'd like to check in: "); scanf("%le", &user_lat); printf("Now enter a corresponding longitude area you'd like to check in: "); scanf("%le", &user_lng); //IF LATITUDE/LONGITUDE VALUES OF THE SHIP ARE WITHIN //USER'S GIVEN VALUES IN ACCORDANCE WITH THE REQUIRED LAT AND LNG //PRODUCE A MESSAGE // THIS LOOP WILL DEAL WITH WHETHER A SHIP IS WITHIN THE BOUNDARIES OF // A USER'S CHOSEN LAT AND LNG VALUES AND ALSO DEAL WITH WHETHER OR NOT SHIP'S // ARE EVEN IN St.George's CHANNEL AT ALL! return (EXIT_SUCCESS); } Now the program runs and lets me enter the latitude and longitude figures but then produces the RUN FAILED error message. For reference here's the output: Please enter a specific latitude value for the vessel: 51.425 0.000000Please enter a specific longitude value for the vessel: 51.233 RUN FAILED (exit value 1, total time: 10s) Anyone got any ideas? To me it should just at the moment take four values from the user :/ Thanks guys, TP12
lightburst Posted March 28, 2012 Posted March 28, 2012 is the structure members latitude and longtitude of type pointer? You need to feed scanf() with a variable of type pointer, e.i. using the address-of operator. Probably just a typo on your part though.
khaled Posted March 29, 2012 Posted March 29, 2012 Here is a compiled code that works fine: C++, C .. I think this is the problem: scanf("%lf", s.latitude); a. if s.latitude is a pointer, it must be allocated before used b. if s.latitude is a variable, it must be preceded by & .. if your code still doesn't work then check these: 1. within the file: main.h 2. why name it main.h (which is assumed to be accompanied with main.c\main.cpp as its definition), change that file name 3. The compiler you're using, try another
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now