#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