Originally Posted by
fenikkusu
Finally find out the way
I used nested structure
...
but is there any shorter way?
IMHO you don't need a nested structure unless it's required of you and there's a shorter way by using a 4 char array as number of cars is limited to 12.
Code:
#include <stdio.h>
void assign_id(void);
typedef struct car
{
char st[4];
int status;
char cus[20];
}car;
car list[12];
int main(void)
{
assign_id();
return 0;
}
void assign_id(void)
{
int i;
for (i=0; i<12; i++)
snprintf(list[i].st,sizeof list[i].st,"C%02d",i+1);
for (i=0; i<12; i++)
printf("ID of car #%d: %s\n",i+1,list[i].st);
}