I've been struggling with PSet2's Vigenere cipher for a few days now, because of one error that I can't seem to fix. Every time I compile this program, the terminal gives me this error: /opt/sandbox50/bin/run.sh: line 31: 11290 Segmentation fault stdbuf --error=0 --output=0 "$@" Also, the cipher seems to be outputting unicode characters instead of actual letters, such as \u0013.
#include <cs50.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, string argv[])
{
string k = argv[1];
int klen = strlen(k);
if (argc != 2)
{
printf("Please enter one argument!\n");
return 1;
}
for (int i = 0; i < klen; i++)
{
if (isalpha(k[i]) == false)
{
printf("Please enter a valid string!");
return 1;
}
}
string p = GetString();
int plen = strlen(p);
for (int j = 0; j < klen; j++)
{
k[j] = toupper(k[j]) - 65;
for (int i = 0; i < plen; i++)
{
if (isalpha(p[i]))
{
p[i] = (p[i] + k[j]) % 26;
printf("%c\n", p[i]);
}
}
}
}