Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- void readLine(char line[], int limit, FILE *fp)
- {
- fgets(line, limit, fp);
- strtok(line, "\n");
- strtok(line, "\r");
- }
- struct info
- {
- char state[20], capital[20], readState[20], readCapital[20];
- double lon, lat;
- };
- int main(){
- struct info in;
- char scanState[20];
- char scanCapital[20];
- int answer = 1;
- FILE *fp;
- printf("What is the state?");
- scanf("%s", &scanState);
- printf("What is the capital?");
- scanf("%s", &scanCapital);
- printf("%s %s\n", scanState, scanCapital);
- fp = fopen("C:\\Users\\The Clone Trooper\\Desktop\\data.txt", "r");
- //checks to make sure that the file was opened correctly
- if (fp == NULL) {
- printf ("Error opening file!\n");
- return 1;
- }
- while(answer == 1){
- while(fscanf(fp, "%s %s %lf %lf", in.state, in.capital, &in.lon, &in.lat) != EOF){
- //printf("Read String1 |%s|\n", in.state );
- //printf("Read String2 |%s|\n", in.capital);
- //printf("Read String3 |%lf|\n", in.lon);
- //printf("Read Integer |%lf|\n", in.lat);
- if((stricmp(in.state, scanState) == 0) && (stricmp(in.capital, scanCapital) == 0)){
- printf("Your coordinates are: %lf , %lf", in.lon, in.lat);
- }
- }
- printf("Would you like to use this tool again? 1 for Yes and 2 for No");
- scanf("%i", &answer);
- }
- fclose(fp);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement