#include <stdio.h>
#include <stdlib.h>
int main()
{
int agecalc;
int nextyr;
int birthday;
int currentday;
int agecalcu;
int randomnumbers;
birthday = 1987;
currentday = 2016;
nextyr = currentday + 1;
agecalc = currentday - birthday;
randomnumbers = 7890;
char My[] = "Sayan Banerjee";
printf("%s 's birthday is %.3d \n", My , agecalc);
agecalcu = agecalc + 1;
/* alternatively I can use one int and change the variable stored in agecalc by stating that
agecalc = currentday - birthday +1; But I think that is just messy and disturbs a lot of code. declaring a new int is
better and less intrusive. this way when I may need to use agecalc again, i dont have to worry about the value stored in that
variable. */
printf("%.5s will turn %.3d on %d.\n \a", My , agecalcu , nextyr);
printf("The username for %s is %.6d \n", My , randomnumbers);
// the thing here is that I cannot shorten a value stored in a value unless its in an array
// but I can express it in other ways like 1 to 01.
/* The thing is that I cannot store two %s in one argument/code. this freezes the code. better way would be to
create another variable and then try to edit that.*/
//this is an experiment to see whether I can take characters from an array and store it in a variable
int user;
My [0,1,2,3,4,5] = user;
printf("%s is also %s", My , user);
return 0;
}
我的主要問題是在最後一行。我是一名編程新手,剛剛開始學習。我只是在玩耍,注意到如果我在同一個參數中輸入兩個%s
,程序就會崩潰。所以,我在考慮是否可以將數組My中的某些字符存儲在變量中,然後將其打印出來?如何從數組中獲取字符並將其存儲在變量中?
可能嗎?或者我只是以錯誤的方式看待這個問題? 對不起,這個雜亂的帖子。 感謝您的幫助。
也有意見,只是我發現周圍的修修補補。我寫的內容可能是錯的,但我只是把整個事情都貼出來。謝謝你的耐心! – returnNULL
歡迎來到StackOverflow。請閱讀[格式化頁面](https://stackoverflow.com/editing-help),這樣你的問題就不會像「混亂」一樣。另外請記住,你總是可以[編輯]你的問題。 – Zeta
順便說一句,如果'x = y'將'y'的值賦給''x'',你的'My ... = user'對你有意義嗎? (我現在沒有時間給出完整的答案,對不起)。 – Zeta