3个错误
jiami (int x)
这个函数最后少了两个}
scanf_s("%d",&choice);
改为
scanf("%d",&choice);
改好的:
#include
#include
char *str=NULL;
char c;
int i = 0;
int choice;
char ch;
jiami (int x)
{
switch(x)
{
case 1:
if((c>='a'&&c<='z') || (c>='A'&&c<='Z'))
{
c=c+3;
if((c>'Z'&&c<='Z'+3 )||( c>'z'))
c=c-26;
return c;
}
break;
case 2:
if((c>='a'&&c<='z') || (c>='A'&&c<='Z'))
{
c=c-3;
if((c<'A')||( c<'a' && c>='a'-3))
c=c+26;
return c;
}
break;
}
}
int main()
{
while(1)
{
printf("\n1.加密 2.解密 3.退出\n");
// scanf_s("%d",&choice);
scanf("%d",&choice);
str = (char *)malloc(1);
printf("请输入密文字符串:");
while((c=getchar())!='\n')
{
jiami (choice);
str[i++] = c;
}
str[i] = 0;
printf("明文字符串为:%s\n",str);
}
}
#include
#include
char *str=NULL;
char c;
int i = 0;
int choice;
char ch;
int jiami (int x)//要有返回值
{
switch(x)
{
case 1:
if((c>='a'&&c<='z') || (c>='A'&&c<='Z'))
{
c=c+3;
if((c>'Z'&&c<='Z'+3 )||( c>'z'))
c=c-26;
return c;
}
break;
case 2:
if((c>='a'&&c<='z') || (c>='A'&&c<='Z'))
{
c=c-3;
if((c<'A')||( c<'a' && c>='a'-3))
c=c+26;
return c;
}
break;
}//少右括号
}//少右括号
int main()
{
while(1)
{
printf("\n1.加密 2.解密 3.退出\n");
scanf_s("%d",&choice);
str = (char *)malloc(1);
printf("请输入密文字符串:");
while((c=getchar())!='\n')
{
jiami (choice);
str[i++] = c;
}
str[i] = 0;
printf("明文字符串为:%s\n",str);
}
return 0;//返回值
}