Advertisement
Guest User

Untitled

a guest
Feb 18th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.19 KB | None | 0 0
  1. void readFiles(FILE *file1, List *theList, int fileNum) {
  2.     int i, lineIndex;
  3.     char *newLine;
  4.  
  5.     size_t lineLength = 0;
  6.     while(lineLength=getline(&newLine, &lineLength, file1)>0){
  7.         lineIndex = 0;
  8.         i = 0;
  9.         char *newWord;//saves individual words
  10.         while(newLine[lineIndex] != '\0'){   //move to new space
  11.             if(newLine[lineIndex] == ' '){
  12.                 //insert(&theList, parseWord(i, newWord), fileNum);
  13.                 parseWord(i, newWord);
  14.                 i = 0;
  15.             }else{
  16.                 newWord[i] = newLine[lineIndex];
  17.                 i++;
  18.             }
  19.             lineIndex++;
  20.         }
  21.     }
  22. }
  23.  
  24. char *parseWord(int theLen, char *theWord){
  25.     char cleanWord[theLen]; //the word without other stuff
  26.     char *finalWord;
  27.     int i, j;
  28.     for(j = i = 0; i < theLen; i++) {
  29.         char tmp = theWord[i];
  30.  
  31.         if (tmp >= 'A' && tmp <= 'Z') {
  32.             cleanWord[j] = tolower((unsigned char) theWord[i]);
  33.             j++;
  34.         } else if ((tmp >= 'a' && tmp <= 'z') || tmp == 39 || tmp == 45) {
  35.             cleanWord[j] = theWord[i];
  36.             j++;
  37.         }
  38.     }
  39.     return strcpy(finalWord, cleanWord);
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement