1

I'm basically trying to read data from a file while ignoring all non alphabetic characters and any characters preceding a non alphabetic would be considered the end of the word and should be inserted into a trie. any ideas? Heres my current code which is getting a seg fault

 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>

 char input;

void readDict(FILE *dict_file)
{
    int line = 0;
    char curr;

    while ( (curr = fgetc(dict_file))!= EOF)
    {
        if(isalpha(curr))
        {
            strcpy(input,curr);
        }
    }
}

int main(int argc, char * argv[])
{
    if (argc < 2)
            printf("invalid input");
    else
    {
        FILE *pFile = fopen(argv[1],"r");
        readDict(pFile);
    }
    return 0;
}
gensou
  • 15
  • 1
  • 7

1 Answers1

1

The segmentation fault is being generated by strcpy. You must pass char * to strcpy as arguments. In the code you posted, both input and curr are of char type.

Read http://www.cplusplus.com/reference/cstring/strcpy/ to understand how to use strcpy.

Pedro Dias
  • 78
  • 2
  • 4