Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <string.h>
- struct Node {
- int timesUsed;
- char* word;
- struct Node* next;
- };
- struct Node* wordList(FILE *fp, struct Node* head);
- struct Node* createNode(struct Node* head, char* word);
- char* title(char* file);//creates file name based on command line input
- int main(int argc, char** argv){
- //Access file information---------------------------------------------
- FILE *fp;
- char* fileName = title(argv[1]);
- fp = fopen(fileName, "r");
- //Define Head node--------------------------------------------------------
- struct Node* head = (struct Node*)malloc(sizeof(struct Node));
- if (head == NULL){
- printf("there is not enough memory on your device to continuen");
- }
- //Access words--------------------------------------------------------
- head = wordList(fp, head);
- printf("%sn",head->word);
- free(head);
- free(fileName);
- return 0;
- }
- //Function that is causing problems==================================
- struct Node* wordList(FILE *fp, struct Node* head){
- char c;
- char wordHolder[1240];//characters
- int j = 0;
- int count = 0;
- do{
- c = getc(fp);
- printf("%cn",c);
- if(isalpha(c) || isdigit(c) || c == '''){
- wordHolder[j] = c;
- j++;
- }
- else{
- if(count){
- char* tempWord = strdup(wordHolder);
- head->word = tempWord;
- head->timesUsed = 1;
- head->next = NULL;
- count = 1;
- j = 0;
- for(i = 0; i< strlen(wordHolder); i++){
- wordHolder[i] = '