c - C语言中字符串的循环

标签 c string

我现在正在做一个关于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/

相关文章:

java - 正则表达式解析多行数据

c - 未引用变量的赋值?

c - 为什么我需要按三次 '\n' 才能运行?

c++ - 网络接口(interface)状态

c - 递归读取数组

python - 在 Python 中拆分 C 文件?

javascript - 反转 JavaScript 中的字符串 : Why is my answer not passing the test?

c++ - 使用引用传递字符串需要进行哪些必要的更改

string - 后缀树如何工作?

C:在c中分配的空闲内存