c - 在c中使用&符号

标签 c

为了解决我在创建一个可以加密和解密字符串(输入)的程序时遇到的问题,我决定创建另一个名为“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/

相关文章:

c - 如何使用 C 获取 Linux 中的 CPU 数量?

c - 禁用 -dkms 错误

c - 当服务器未启动时,无法与服务器建立重复的 SOCK_STREAM 连接?

c - C 中指针语法的初学者

计算两个不同日期的两次时间之差

c - 如何清除传递给 C 函数的 char*?

c - 在 C 中错误地打印输出;故障和重复

C、fork()中的一些语句没有执行

c - 为什么这段代码在c中会失败?

c - 使用 C API 获取 SQLite 语句受影响的行数