This code prints the Months and how many days it has.
I want to make my code short, I thought that I use some for loop and make the name of the months in array but I cant think how.
If I make the jan.month to a for loop and make it i.month, i dont get how i will change the month name...
Can anyone help me a bit?
Code:#include<string.h> #include<stdio.h> #include<stdlib.h> struct item { char month[80]; int date; } disp(struct item it) { printf("%s %d \n", it.month, it.date); } int main() { struct item jan;struct item feb;struct item mar; struct item apr;struct item may;struct item jun; struct item jul;struct item aug;struct item sep; struct item oct;struct item nov;struct item dec; strcpy( jan.month, "January"); strcpy( feb.month, "February"); strcpy( mar.month, "March"); strcpy( apr.month, "April"); strcpy( may.month, "May"); strcpy( jun.month, "June"); strcpy( jul.month, "July"); strcpy( aug.month, "August"); strcpy( sep.month, "September"); strcpy( oct.month, "October"); strcpy( nov.month, "November"); strcpy( dec.month, "December"); jan.date=30; feb.date=28; mar.date=30; apr.date=28; may.date=30; jun.date=28; jul.date=30; aug.date=28; sep.date=30; oct.date=28; nov.date=30; dec.date=28; disp(jan); disp(feb); disp(mar); disp(apr); disp(may); disp(jun); disp(jul); disp(aug); disp(sep); disp(oct); disp(nov); disp(dec); system("pause"); }