Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include "stdafx.h"
- #include <string.h>
- void main()
- {
- FILE *fptr;
- int i;
- char names[100][12];
- fptr = fopen("F:\\surnames.txt", "r");
- char word[80];
- int count = 0;
- if (fptr == NULL)
- {
- printf("Error loading file! \n");
- }
- else
- {
- printf("Choose a name.\n");
- scanf("%s", word);
- i = 0;
- while (!feof(fptr))
- {
- fscanf(fptr, "%s\n", names[i]);
- if (!strcmp(names[i], word))//if match found increment count
- count++;
- i++;
- }
- printf("Name %s occured %d times\n", word, count);
- getchar();
- }
- fclose(fptr);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement