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){


closed as off-topic by Jenny D, womble Jun 22 '18 at 1:11

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on Server Fault must be about managing information technology systems in a business environment. Home and end-user computing questions may be asked on Super User, and questions about development, testing and development tools may be asked on Stack Overflow." – womble
If this question can be reworded to fit the rules in the help center, please edit the question.


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
  • I'll test it tomorrow, I have a test today, thank you. – Arturo Jun 18 '18 at 17:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.