#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;
}
The main question I have is in the last line. I am a newbie to coding and have just started learning. I was just playing around and noticed that if I put in two %s
in the same argument the program kind of crashes. So, I was thinking if I can take certain characters in the array My and store them in a variable and then print it?
Is it possible? or am I just looking at this in the wrong way? Sorry for the messy post. Thanks for all your help.