0

When I run vigenere I get the message Segmentation fault (core dumped). I understand that this means that I am accessing memory that should not be accessed, but I do not see why or how. I begin with argc = 2. I am trying to save the second string argv[1] as my key variable. Then I use isalpha to determine if it is a letter. I error out of the program if it is not.

On a related note I tried to use gdb but it kept asking me for a file. Can I use the debugger for this type of problem?

1
2

This:

if isalpha(key)

isalpha() works on a char, and you've given it a string. That will segfault. You need to check each individual char, so think of using a loop.

To run in gdb:

gdb ./vigenere
...
(gdb) run abc

will run it with key of abc

2
  • Thanks, using a loop and checking each letter seems to have worked! (It probably would be wise to create an isString function; not entirely how to do that.) Anyway I am more focused in getting to the end of the problem. Thanks again! – William Kenney Sep 3 '14 at 8:49
  • A string is really an array of chars, so probably an isString function would use a loop. :) Glad to have helped. Please mark the answer as accepted too so others know it has been answered. – curiouskiwi Sep 3 '14 at 8:50
0

isalpha() returns a number > 0 if there is an alphabetic character in the parentheses, and 0 if not.

Also, "key" is a string and isalpha() only accepts characters.

You must log in to answer this question.

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