예제 #1
0
파일: search.c 프로젝트: BrianB86/Bad-Grep
/* Extension of SLSearch, because I don't want to be messy and creating
 * structs to search for words inside of other methods. Keep that here.
 */ 
int SLSearchWord(SortedListPtr head, char* word)
{
	WordPtr target = createWordStruct(word);
	void *castToSearch = (void*)target;
	int result = SLSearch(head,castToSearch);
	target->filestats = NULL;
	destroyWordStruct(target);
	return result;
}
예제 #2
0
파일: search.c 프로젝트: BrianB86/Bad-Grep
/* Given a word line, extract the word from the line.
 * 
 */ 
WordPtr extractWord(char *line)
{
	//I just want to take every character in the line EXCEPT the first 7
	//The first 7 will be <List>  
	char *newWord = (char*)malloc((strlen(line) - 6));
	strcpy(newWord,&line[7]);
	WordPtr newWordStruct = createWordStruct(newWord);
	//printf("Extracted word %s\n",newWord);
	free(newWord);
	return newWordStruct;
}
예제 #3
0
int main()
{
    Node * head = NULL;
    FILE * fin = NULL;

    fin = openFile();

    createWordNodes(fin,&head);


    printf("\n\n-----------Printing Original List-----------\n\n");
    printList(head);
    printf("\n\n\nBREAK\n\n\n");

    char temp[6] = "frank";
    Word * tempWord = createWordStruct(temp);

    addOrdered(tempWord, &head);
    printf("\n\n-----------Printing List Adding Ordered the name \"frank\"-----------\n\n");
    printList(head);
    printf("\n\n\nBREAK\n\n\n");

    char temp1[6] = "AAAAA";
    tempWord = createWordStruct(temp1);

    addFirst(tempWord, &head);
    printf("\n\n-----------Printing List Adding First the word \"AAAAA\"-----------\n\n");
    printList(head);
    printf("\n\n\nBREAK\n\n\n");

    char temp2[6] = "ZZZZZ";
    tempWord = createWordStruct(temp2);

    addLast(tempWord, &head);
    printf("\n\n-----------Printing List Adding Last the word \"ZZZZZ\"-----------\n\n");
    printList(head);
    printf("\n\n\nBREAK\n\n\n");

    char temp3[6] = "XXXXX";
    tempWord = createWordStruct(temp3);

    addIndexed(tempWord, &head, 2);
    char prevWord[MAX], postWord[MAX];
    strcpy(prevWord,((Word*)(head->next->data))->wrd);
    strcpy(postWord,((Word*)(head->next->next->next->data))->wrd);


    printf("\n\n-----------Printing List Adding at Index #2 the word \"XXXXX\"-----------\n\n");
    printf("\n\n-----------It should be between the words \"%s\" and \"%s\"-----------\n\n", prevWord, postWord);
    printList(head);
    printf("\n\n\nBREAK\n\n\n");

    removeFirst(&head);
    printf("\n\n-----------Printing List Removing First which will be the word \"AAAAA\"-----------\n\n");
    printList(head);
    printf("\n\n\nBREAK\n\n\n");

    removeLast(&head);
    printf("\n\n-----------Printing List Removing Last which will be the word \"ZZZZZ\"-----------\n\n");
    printList(head);
    printf("\n\n\nBREAK\n\n\n");

    printf("\n\n-----------Attempting to remove at index out of bounds-----------\n\n");
    removeIndex(&head,-30);

    char word2Remove[MAX];
    strcpy(word2Remove,((Word*)(head->next->next->data))->wrd);

    printf("\n\n-----------Attempting to remove at index 2 which will be: \"%s\"-----------\n\n", word2Remove);
    removeIndex(&head, 2);


    printf("\n\n-----------Printing list having removed %s-----------\n\n", word2Remove);
    printList(head);
    printf("\n\n\nBREAK\n\n\n");



    printf("\n\n-----------Clearing (freeing) the entire list-----------\n\n");
    clearList(&head);

    printf("\n\n-----------Attempting to print empty list-----------\n\n");
    printList(head);
    printf("\n\n\nBREAK\n\n\n");

    printf("\n\n-----------GOODBYE-----------\n\n");

    fclose(fin);
	return 0;

}// end main