[英]Using ampersand in 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]);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.