0

我可能会对我的问题进行一些审查,但在这一点上,我会尽我所能。我将尝试一步一步地让我遇到的问题尽可能简单。

我试着:

Read in a .txt file of keywords
print them
read in .txt resume(the program is a resume scanner)
search the resume for the keywords
output the keyword with the count of ho many times they were used.

我可以同时输出简历数组和关键字数组,但是当我到达搜索和输出部分时,它会中断。我想看看我是否接近我的搜索代码。

我的教授不久前给了我们这个作业,我无法弄清楚它的搜索和输出部分。现在我有一些空闲时间,我想回去尝试解决它,但没有运气。下面是我的代码。我想为篇幅道歉,我不是想用一堆代码来爆破这篇文章,但我觉得它都是相关的。如果我至少能学到这一点,我会在这里接受坏代表。我觉得这真的很重要。谢谢大家!

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include <stdlib.h>
#define pause system("pause")
#define cls system("cls")
#include <string.h>


main(){
FILE* pFile;
FILE* resume;
char f[50] = { "" };
char r[50] = { "" };
char search = "";
int i = 0, j = 0;
int count = 0, c = 0;

printf("Read in the keywords\n\n");//read in keywords
pFile = fopen("a:\\newA.txt", "r");
if (!pFile) {
    perror("Error");
}
fread(f, sizeof(char), 50, pFile);//read in keywords into char array
for (i = 0; i<50; i++) {
    if (f[i] == ',') {
        printf("\n");
    }
    else {
        printf("%c", f[i]);
    }
}//end for loop
printf("\n\n");
pause;//end reading in keywords

//read in resume
cls;
resume = fopen("a:\\resume.txt", "r");
if (!resume) {
    perror("Error");
}
    fread(r, sizeof(char), 50, resume);//read in resume into char array
    for (j = 0; j < 50; j++) {
        if (r[j] == ',') {
            printf("\n");
        }
        else {
            printf("%c", r[j]);
        }
}//end for loop
    printf("\n\n");
    pause;
// end reading in resume

下面是我休息的地方

//beginning search
for (c = 0; c < i; c++)
{
    if (f[i] == r[c])//if keyword match resume add counter
    {
        count++;//counter
    }
}//end for loop
if (count == 0)
    printf("\n%s is not present in array.\n", search);//no matches
else
    printf("\n%s is present %d times in array.\n\n", search, count);//keyword match and how many times found

pause;//end search and output

}
4

0 回答 0