Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. void readFile() {
  2. FILE * ifp = fopen("countries.list", "r");
  3. if (ifp == NULL) {
  4. fprintf(stderr, "Can't open input file countries.list!\n");
  5. exit(1);
  6. }
  7.  
  8. FILE * ofp = fopen("results.list", "w");
  9. if (ofp == NULL) {
  10. fprintf(stderr, "Can't open output file results.list\n");
  11. exit(1);
  12. }
  13.  
  14. char country[50];
  15. char capital[50];
  16. while (fscanf(ifp, "%s %s", capital, country) != EOF) {
  17. list.countries[list.count] = (char*)malloc(strlen(country));
  18. list.capitals[list.count] = (char*)malloc(strlen(capital));
  19. memcpy(list.countries[list.count], country, strlen(country));
  20. memcpy(list.capitals[list.count], capital, strlen(capital));
  21.  
  22. printf("country: %s \n", list.countries[list.count]);
  23. printf("cap: %s \n", list.capitals[list.count]);
  24.  
  25. list.count++;
  26.  
  27. memset(country, 0, 50);
  28. memset(capital, 0, 50);
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement