我现在正在做一个关于cookie订购系统的作业,那里有一个“订单号”。我想以“TARC 000XX”格式显示我的订单号。那么我该如何输入这种格式呢?由于它是一个订购系统,所以我想循环这个订单号(每个客户都会有不同的订单号 - 第一个客户是 TARC 00001,第二个客户是 TARC 00002 等等) 那么,如果下一个客户想要订购,我该如何循环此操作以使订单号不断变化?
最佳答案
你可以做这样的事情
int order_number = 1;
printf("TARC %05d\n", order_number);
order_number++;
它将格式化要打印的字符串,例如“TARC 00001”然后“TARC 00002”等。
编辑:在循环的上下文中,它可能看起来像这样
for (int order_num = 1; order_num <= max_num_orders; order_num++) {
printf("TARC %05d\n", order_num);
/* Do other stuff with current order if needed */
}
关于c - C语言中字符串的循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56986225/