Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include <stdio.h>
  2. #include "stdafx.h"
  3. #include <string.h>
  4.  
  5. void main()
  6. {
  7. FILE *fptr;
  8. int i;
  9. char names[100][12];
  10. fptr = fopen("F:\\surnames.txt", "r");
  11. char word[80];
  12. int count = 0;
  13.  
  14. if (fptr == NULL)
  15. {
  16. printf("Error loading file! \n");
  17. }
  18. else
  19. {
  20. printf("Choose a name.\n");
  21. scanf("%s", word);
  22. i = 0;
  23. while (!feof(fptr))
  24. {
  25. fscanf(fptr, "%s\n", names[i]);
  26. if (!strcmp(names[i], word))//if match found increment count
  27. count++;
  28. i++;
  29. }
  30. printf("Name %s occured %d times\n", word, count);
  31. getchar();
  32.  
  33. }
  34. fclose(fptr);
  35.  
  36.  
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement