Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. void readLine(char line[], int limit, FILE *fp)
  6. {
  7. fgets(line, limit, fp);
  8. strtok(line, "\n");
  9. strtok(line, "\r");
  10. }
  11.  
  12. struct info
  13. {
  14. char state[20], capital[20], readState[20], readCapital[20];
  15. double lon, lat;
  16. };
  17.  
  18. int main(){
  19. struct info in;
  20.  
  21. char scanState[20];
  22. char scanCapital[20];
  23. int answer = 1;
  24.  
  25. FILE *fp;
  26.  
  27.  
  28. printf("What is the state?");
  29. scanf("%s", &scanState);
  30. printf("What is the capital?");
  31. scanf("%s", &scanCapital);
  32. printf("%s %s\n", scanState, scanCapital);
  33.  
  34. fp = fopen("C:\\Users\\The Clone Trooper\\Desktop\\data.txt", "r");
  35. //checks to make sure that the file was opened correctly
  36. if (fp == NULL) {
  37. printf ("Error opening file!\n");
  38. return 1;
  39. }
  40.  
  41. while(answer == 1){
  42. while(fscanf(fp, "%s %s %lf %lf", in.state, in.capital, &in.lon, &in.lat) != EOF){
  43. //printf("Read String1 |%s|\n", in.state );
  44. //printf("Read String2 |%s|\n", in.capital);
  45. //printf("Read String3 |%lf|\n", in.lon);
  46. //printf("Read Integer |%lf|\n", in.lat);
  47.  
  48. if((stricmp(in.state, scanState) == 0) && (stricmp(in.capital, scanCapital) == 0)){
  49. printf("Your coordinates are: %lf , %lf", in.lon, in.lat);
  50. }
  51.  
  52. }
  53. printf("Would you like to use this tool again? 1 for Yes and 2 for No");
  54. scanf("%i", &answer);
  55. }
  56.  
  57.  
  58.  
  59. fclose(fp);
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement