void words(FILE *in,char *current_word){
char punctuation[]= ". ,;:*!?'-\n\0\r";
char c = fgetc(in);
int i = 0;
while(strchr(punctuation,c) == NULL){
current_word[i] = c;
i++;
c = fgetc(in);
}
current_word[i] = '\0';
}
int main(){
FILE *in = fopen("file.txt","r");
while(!feof(in)){
char current_word[30];
char *cw = current_word;
words(in,cw);
printf("%s",current_word);
}
}
So I read from a file, create my own array current_word
, make a pointer to that array so I edit it later. I call the words function that has an array of punctuation
marks. While none of the characters I take from the file are any of these punctuation marks I add them to the current_word array which is pointed to by the pointer I passed into the function words
.
I probably missing some knowledge on pointers.
This is continuously giving me the error Segmentation fault