为了解决我在创建一个可以加密和解密字符串(输入)的程序时遇到的问题,我决定创建另一个名为“char passb[81]”的数组
这个新数组的目的是存储输入对应的大写字符。这些字符将在我的程序的其他部分中使用。我已包含以下代码。
int plength;
char pass[81];
printf("Please enter passphrase: \n");
scanf("%s", &pass);
plength=("%d", strlen(pass));
{
char passb[81];
int p;
for (p=0; p<plength; p++)
{
if(pass[p] >= 97 && pass[p] <= 122)
{
return((pass[p]-32), &passb);
}
else if (pass[p] >= 65 && pass[p] <= 90)
{
return((pass[p]), &passb);
}
}
printf("\n");
}
当我尝试编译程序时,收到以下错误消息:
test2.c: In function ‘main’:
test2.c:50:6: warning: return makes integer from pointer without a cast
return((pass[p]-32), &passb);
^
test2.c:50:6: warning: function returns address of local variable [-Wreturn- local-addr]
test2.c:54:6: warning: return makes integer from pointer without a cast
return((pass[p]), &passb);
^
test2.c:54:6: warning: function returns address of local variable [-Wreturn-local-addr]
我可以做什么来解决这个问题?任何贡献和回应将不胜感激。
最佳答案
那里不需要 return 语句,只需要一个赋值:
if(pass[p] >= 97 && pass[p] <= 122)
{
passb[p] = pass[p]-32;
}
else //don't need this either if (pass[p] >= 65 && pass[p] <= 90)
{
passb[p] = pass[p];
}
所有这些都可以替换为:
passb[p] = toupper(pass[p]);
关于c - 在c中使用&符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33487143/