0

I'm doing an assignment for school using getop with ocelot, I have to count words and count the substrings in the document. I have the word counting working but I was not able to do the substring, I can only get to read/display what substring the user wants, that's what the program is about. Now, when I put for example on the commandline:

./hello -c -f substringToFind test.txt 

it works but that's because the file test exists, if I say for example: ./hello -c -f hd test

it would give me a segmentation fault. How can I read if it was a s. fault and display a message? ex:

if(segmentation fault){ printf("..."); exit(1) } 

Thanks

1 Answer 1

1

This might be better answered in stackoverflow.com than here. I'm also guessing you meant getopt instead of getop.

If I'm getting your problem correctly, you might want to check for the file instead of the segmentation fault:

if( access( filename, F_OK ) != -1 ) { // file exists } else { // file doesn't exist } 
1
  • I'll test it tomorrow, I have a test today, thank you. Commented Jun 18, 2018 at 17:20

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.