0

The following is my code for pset2 initials 2017 and I got a segmentation error. Can someone plse help me debug this.

Now here's the output :

Hello what's your name?
ansh parashar                                                                    
APSegmentation fault

Please help me find the way to fix this segmentation fault.

1 Answer 1

0

The expression 1 <= n <= strlen(name) is too direct for C. You have to write it as (1 <= n) && (n <= strlen(name)) . Also, in C (and most other languages) a string is zero-indexed (first element starts at index 0) so you can use n < strlen(name).

5
  • I tried implementing ur suggestion but sorry it didn't work . Any more suggestions to help ?
    – sk.76
    Commented Jun 10, 2017 at 8:11
  • same error of segmentation fault? Commented Jun 10, 2017 at 9:22
  • Ya , I got the same segmentation error. Plse help.
    – sk.76
    Commented Jun 10, 2017 at 12:29
  • i tried running your code. I did get the segmentation fault as well. Then i corrected the while statement to while(1 <= n && n < strlen(name)) and then i worked fine... Commented Jun 10, 2017 at 13:43
  • Ya no error this time ! Thanks for help.
    – sk.76
    Commented Jun 10, 2017 at 16:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .