我的目標是接受用戶的輸入,然后列印字母系列。從用戶輸入的點開始列印字母系列。
#include<stdio.h>
int main(){
char alpha_U;
printf("Enter the letter from where you want in upper case: ");
scanf("%c",alpha_U);
for(char i = alpha_U; i <= 'Z'; i ){
printf("%c",i);
}
return 0;
}
uj5u.com熱心網友回復:
你的代碼幾乎沒問題,除了
scanf("%c", alpha_U);
這需要一個指標作為第二個引數。
我不是 C 或 C 編程專家,所以我建議您查看 cplusplus.com 上的檔案。
具體來說,以下是 scanf 的記錄方式:
https://cplusplus.com/reference/cstdio/scanf/
附加引數應指向已分配的物件,其型別由格式字串中的相應格式說明符指定。
所以在你的情況下你應該做
scanf("%c", &alpha_U);
uj5u.com熱心網友回復:
#include<stdio.h>
int main()
{
char alpha_U;
printf("Enter the letter from where you want in upper case: ");
scanf("%c", &alpha_U);//Here,you should add '&' before 'alpha_U'
for (char i = alpha_U; i <= 'Z'; (int)i ) {//Then,add '(int)' before 'i'
printf("%c", i);
}
return 0;
}
uj5u.com熱心網友回復:
我也是 C 的初學者,所以如果我錯過了任何細節,我會很高興。
scanf("%c", alpha_U);
缺少 & 在變數的前面。更正如下。
scanf("%c",&alpha_U);
我重寫了代碼,以便可以在主函式中獲取用戶輸入。
#include<stdio.h>
#include <ctype.h>
int main(int argc, char *argv[]){
char lowerCase,upperCase;
printf("Enter one chacters to be capitalized\n");
scanf("%c", &lowerCase);
upperCase = toupper(lowerCase);
printf("%c",upperCase);
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/492610.html
下一篇:在C中列印結構的問題
