Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 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. char answer = 'y';
  24.  
  25.  
  26. while(answer == 'y'){
  27. FILE *fp;
  28.  
  29. printf("What is the state?");
  30. scanf("%s", &scanState);
  31. printf("What is the capital?");
  32. scanf("%s", &scanCapital);
  33. printf("%s %s\n", scanState, scanCapital);
  34.  
  35. fp = fopen("C:\\Users\\The Clone Trooper\\Desktop\\data.txt", "r");
  36. //checks to make sure that the file was opened correctly
  37. if (fp == NULL) {
  38. printf ("Error opening file!\n");
  39. return 1;
  40. }
  41.  
  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\n", in.lon, in.lat);
  50. }
  51.  
  52.  
  53.  
  54. }
  55. printf("Would you like to use this tool again? y for Yes and n for No\n");
  56. scanf(" %c", &answer);
  57. fclose(fp);
  58. }
  59. printf("Thank you for using this tool!");
  60.  
  61.  
  62.  
  63.  
  64. return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement