0

I inputted Bill Carroll with the key 'key' and got BBBBBBBBBBiii. I can't seem to figure out what I am doing wrong. My code is as follows.

#include <stdio.h>
#include <cs50.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

int main(int argc, string argv[])
{
    // checks usage
    if (argc != 2)
    {
        printf("\nUsage: ./vigenere <key>\n\n");
        return 1;
    }
    else
    {
        int key = atoi(argv[1]);

[EDIT: remaining, irrelevant code removed for Honor Code compliance.]
2
  • You have a very basic misconception from what I understand. argc holds the number of parameters given when the program was run. Not their length.
    – ChrisG
    Aug 14 '15 at 18:35
  • Plus the fact that in contrary to caesar, in vigenere the key won't be an integer, so you shouldn't use atoi.
    – ChrisG
    Aug 14 '15 at 18:39
2

The program calls for entry of a text string for the key. Your code, probably cut and pasted from the previous part of the exercise, attempts to convert argv[1] to an integer. Since argv[1] is a string, it causes seg faults later.

If this answers your question, please click the check mark to accept this and remove the question from the unanswered pool. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

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