诺比在这里。弹出打开我的虚拟机以编辑程序,但是(据我所知),在我进行任何更改之前,我遇到了以前没有发生的分段错误。我尝试评论可能的原因,但无济于事。
#include <stdio.h>
#include <cs50.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main (int argc, string argv[])
{
int keyOk = 0;
string keyword = argv[1];
int keyLength = strlen(keyword);
do
{
if (argc != 2)
{
printf("TOo many words\n");
return 1;
}
else
{
for (int i = 0; i < keyLength; i++)
{
if(isalpha(keyword[i] == 0 ))
{
printf("Only use alpha\n");
return 1;
}
}
keyOk = 1;
}
}
while(keyOk == 0);
string cipherInput = GetString();
int cipherLength = strlen(cipherInput);
int j = 0;
for(int i = 0; i < cipherLength; i++)
{
if(isalpha(cipherInput[i]))
{
if(islower(keyword[j]))
{
if(islower(cipherInput[i]))
{
printf("%c", ((((cipherInput[i] - 97)+(keyword[j]-97))%26)+97));
}
else
{
printf("%c", ((((cipherInput[i] - 65)+(keyword[j]-97))%26)+65));
}
}
else
{
if(islower(cipherInput[i]))
{
printf("%c", ((((cipherInput[i] - 97)+(keyword[j]-65))%26)+97));
}
else
{
printf("%c", ((((cipherInput[i] - 65)+(keyword[j]-65))%26)+65));
}
}
j = i % cipherLength;
}
else
{
printf("%c", cipherInput[i]);
}
}
//printf("%s\n", keyword);
printf("\n");
}
GDB 输出,我不知道它是什么意思。通常它只是给我一个行号......
New LWP 31749]
Core was generated by `./vigenere'.
Program terminated with signal 11, Segmentation fault.
#0 __strlen_sse2_bsf () at ../sysdeps/i386/i686/multiarch/strlen-sse2-bsf.S:50
50 movdqu (%edi), %xmm1