我目前正在学习cs50课程,我对习题集2(凯撒)有意见。我试着运行下面的代码,但它给了我一个**分段错误**警告,但我似乎无法自己发现问题。
请问问题是什么,我该如何解决?
#include <cs50.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
bool only_digits(string s);
int main(int argc, string argv[])
{
int i,n;
string text;
n = strlen(text);
string s = argv[1];
int k = atoi(argv[1]);
if (argc != 2 || !only_digits(s))
{
printf("Usage: ./caesar key\n");
return 1;
}
text = get_string("plaintext: ");
for(i=0; i<n; i++)
{
if(isupper(text[i]))
{
char r, z;
r = text[i] + k;
while (r>90)
{
z = r-90;
text[i]= 64 + z;
}
}
if(!isalpha(text[i]))
{
text[i]= text[i]+0;
}
}
}
bool only_digits(string s)
{
int i;
int n = strlen(s);
for (i=0; i<n; i++)
{
if(!isdigit(s[i]))
{
return false;
}
}
return true;
}