Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Shane Davis
- // Function of the program is to take an input resume and input keywords and count how many times the keywords appear in the resume
- // DOES NOT WORK, the counting portion of the program does not work. See below for more information
- #define _CRT_SECURE_NO_DEPRECATE
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <time.h>
- #define pause system("pause")
- #define clrcmd system("CLS")
- // Function Prototypes
- void loadTxt(char* resume, char* keywords);
- void main()
- {
- // Declaring Variables
- char resume[1000] = { '\0' }, keywordInput[1000] = { '\0' }; // Strings that will contain the resume from the resume.txt and the keywords from keywords.txt
- char keywords[100][100]; // 2D character array that stores each individual keyword seperately
- // Keyword
- // 0 keyword0
- // 1 keyword1
- // 100 keyword100
- for (int i = 0; i < 100; i++) // Filling keywords with null characters so that the output isnt a complete mess
- {
- for (int j = 0; j < 100; j++)
- {
- keywords[i][j] = '\0';
- }
- }
- int keywordPos = 0; // Tracks the position of the first part of the entry for keywords[][]
- int keywordInputPos = 0; // Tracks the amount of characters in each keyword so that it can be assigned to the second part in keyword[][]
- int keywordCount = 0; // Total count from the amount of keywords in the resume
- // Import the words from the .txt files
- loadTxt(resume, keywordInput);
- // Seperate keywordInput into individual entries in keywords
- for (int i = 0; keywordInput[i] != '\0'; i++)
- {
- if (keywordInput[i] != ',')
- {
- keywords[keywordPos][keywordInputPos] = keywordInput[i];
- keywordInputPos++;
- } else
- {
- keywordPos++;
- keywordInputPos = 0;
- }
- }
- // The magic
- char* token = { '\0' };
- char tempResume[1000] = { '\0' };
- for (int i = 0; i < 1000; i++)
- {
- tempResume[i] = resume[i];
- }
- token = strtok(tempResume, "., ");
- while (token != NULL)
- {
- for (int i = 0; i < keywordPos+1; i++)
- {
- if (strcmp(token, keywords[i]) == 0)
- {
- keywordCount++;
- }
- }
- token = strtok(NULL, "., ");
- }
- // Display output
- printf("Input from resume: %s\n"
- "Input and separated keywords: "
- ,resume);
- for (int i = 0; i < 100; i++)
- {
- printf("%s ", keywords[i]);
- }
- printf("\nKeywords Counted: %d words", keywordCount);
- }
- void loadTxt(char* resume, char* keywords)
- {
- FILE* resumeTxt, * keywordsTxt; // File pointers to their respective files
- // Open, scan, and close the resume.txt
- resumeTxt = fopen("resume.txt", "r+");
- fread(resume, 1, 1000, resumeTxt);
- fclose(resumeTxt);
- // Open, scan, and close the keywords.txt
- keywordsTxt = fopen("keywords.txt", "r");
- fread(keywords, 1, 1000, keywordsTxt);
- fclose(keywordsTxt);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement