我可能会对我的问题进行一些审查,但在这一点上我将采取我能得到的任何东西。我将尝试在一步一步的目标中尽可能简单地解决我遇到的问题。
我试图:
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.
我可以输出resume数组和关键字数组,但是当我到达搜索和输出部分时它会中断。我试着看看我是否接近我的搜索代码。
我的教授不久前给了我们这个任务,我无法弄清楚它的搜索和输出部分。现在我有一些空闲时间,我想回去尝试找出它没有运气。以下是我的代码。我想为这个长度道歉,我不是想用一堆代码来宣传这篇文章,但感觉它的全部相关。如果我至少可以学习这个,我会在这里接受不好的代表。我觉得这很重要。提前谢谢大家!
#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
}