SHARE
TWEET

Untitled

a guest Oct 14th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Shane Davis
  2. // Function of the program is to take an input resume and input keywords and count how many times the keywords appear in the resume
  3. // DOES NOT WORK, the counting portion of the program does not work. See below for more information
  4. #define _CRT_SECURE_NO_DEPRECATE
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <time.h>
  9. #define pause system("pause")
  10. #define clrcmd system("CLS")
  11.  
  12. // Function Prototypes
  13. void loadTxt(char* resume, char* keywords);
  14.  
  15. void main()
  16. {
  17.     // Declaring Variables
  18.  
  19.     char resume[1000] = { '\0' }, keywordInput[1000] = { '\0' }; // Strings that will contain the resume from the resume.txt and the keywords from keywords.txt
  20.     char keywords[100][100]; // 2D character array that stores each individual keyword seperately
  21.                                           //     Keyword
  22.                                           // 0   keyword0
  23.                                           // 1   keyword1
  24.                                           // 100 keyword100
  25.     for (int i = 0; i < 100; i++) // Filling keywords with null characters so that the output isnt a complete mess
  26.     {
  27.         for (int j = 0; j < 100; j++)
  28.         {
  29.             keywords[i][j] = '\0';
  30.         }
  31.     }
  32.    
  33.     int keywordPos = 0; // Tracks the position of the first part of the entry for keywords[][]
  34.     int keywordInputPos = 0; // Tracks the amount of characters in each keyword so that it can be assigned to the second part in keyword[][]
  35.     int keywordCount = 0; // Total count from the amount of keywords in the resume
  36.  
  37.     // Import the words from the .txt files
  38.     loadTxt(resume, keywordInput);
  39.  
  40.     // Seperate keywordInput into individual entries in keywords
  41.     for (int i = 0; keywordInput[i] != '\0'; i++)
  42.     {
  43.         if (keywordInput[i] != ',')
  44.         {
  45.             keywords[keywordPos][keywordInputPos] = keywordInput[i];
  46.             keywordInputPos++;
  47.  
  48.         } else
  49.         {
  50.             keywordPos++;
  51.             keywordInputPos = 0;
  52.         }
  53.        
  54.     }
  55.  
  56.     // The magic
  57.     char* token = { '\0' };
  58.     char tempResume[1000] = { '\0' };
  59.     for (int i = 0; i < 1000; i++)
  60.     {
  61.         tempResume[i] = resume[i];
  62.     }
  63.     token = strtok(tempResume, "., ");
  64.     while (token != NULL)
  65.     {
  66.         for (int i = 0; i < keywordPos+1; i++)
  67.         {
  68.             if (strcmp(token, keywords[i]) == 0)
  69.             {
  70.                 keywordCount++;
  71.             }
  72.         }
  73.         token = strtok(NULL, "., ");
  74.     }
  75.  
  76.  
  77.     // Display output
  78.     printf("Input from resume: %s\n"
  79.            "Input and separated keywords: "
  80.            ,resume);
  81.     for (int i = 0; i < 100; i++)
  82.     {
  83.         printf("%s ", keywords[i]);
  84.     }
  85.     printf("\nKeywords Counted: %d words", keywordCount);
  86. }
  87.  
  88. void loadTxt(char* resume, char* keywords)
  89. {
  90.     FILE* resumeTxt, * keywordsTxt; // File pointers to their respective files
  91.  
  92.     // Open, scan, and close the resume.txt
  93.     resumeTxt = fopen("resume.txt", "r+");
  94.     fread(resume, 1, 1000, resumeTxt);
  95.     fclose(resumeTxt);
  96.  
  97.     // Open, scan, and close the keywords.txt
  98.     keywordsTxt = fopen("keywords.txt", "r");
  99.     fread(keywords, 1, 1000, keywordsTxt);
  100.     fclose(keywordsTxt);
  101. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top