Hocam, günlerdeki th, rd, nd ayrıntısını nasıl araya koyabilirim?
[CODE lang="c" title="C"]
main(){
int day,month,year;
char ch[2];
printf("Enter date (dd/mm/yy): ");
scanf("%d/%d/%d", &day,&month,&year);
if(day==1){
ch[0]='s';
ch[1]='t';
}
else if(day==2){
ch[0]='n';
ch[1]='d';
}
else if(day==3){
ch[0]='r';
ch[1]='d';
}
else{
ch[0]='t';
ch[1]='h';
}
switch(month){
case 1:
printf("Dated this %d%s day of %s, %d",day,ch,"January",year);
break;
case 2:
printf("Dated this %d%s day of %s, %d",day,ch,"February",year);
break;
case 3:
printf("Dated this %d%s day of %s, %d",day,ch,"March",year);
break;
case 4:
printf("Dated this %d%s day of %s, %d",day,ch,"April",year);
break;
case 5:
printf("Dated this %d%s day of %s, %d",day,ch,"May",year);
break;
case 6:
printf("Dated this %d%s day of %s, %d",day,ch,"June",year);
break;
case 7:
printf("Dated this %d%s day of %s, %d",day,ch,"July",year);
break;
case 8:
printf("Dated this %d%s day of %s, %d",day,ch,"August",year);
break;
case 9:
printf("Dated this %d%s day of %s, %d",day,ch,"September",year);
break;
case 10:
printf("Dated this %d%s day of %s, %d",day,ch,"October",year);
break;
case 11:
printf("Dated this %d%s day of %s, %d",day,ch,"November",year);
break;
case 12:
printf("Dated this %d%s day of %s, %d",day,ch,"December",year);
break;
}
}[/CODE]
Şöyle düzenledim. Günü okuduktan sonra ilk üç gün için özel durum var st,nd,rd gerisi th. Bunu karakter arrayinin (string) içinde tutarak günün yanında bastırdım.