C文件名格式帮助 [英] C file name format help

查看:86
本文介绍了C文件名格式帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用普通C.
我从数据库得到的响应是,数据库中有多少个文档可用.

我需要创建一个包含有关该文档信息的文件.
文件名具有特定格式.格式为x000001.PDF
在哪里,
x:文档类型
000001:是数字
PDF:扩展名
因此,对于每个响应,我都需要更改000001,000002,000003,以此类推....

请帮我解决该问题.
rignt现在我使用了硬编码值.

Hi,

I am using plain C.
I am getting responses from database that how many documents are available in DB.

I need to create a file which conains the information about that document.
Filename has specific format. The format is x000001.PDF
where,
x: document type
000001: is incnumber
PDF: extension
So for each response I need to change the 000001,000002,000003, etc....

Please help me out how can I do this.
rignt now I had used hard coded value.

char Incnumber[7] = "000001";
sprintf(filename,"%s%s.%s",type,Incnumber,"PDF");

FILE *fptr = fopen(filename,"w+");

.....

在此先感谢您.

.....

Thanks in advance.

推荐答案

您已经在使用sprintf,因此请尝试以下操作:

You are already using sprintf, so try this:

sprintf(filename,"%s%07d.%s", type, i, "PDF");



%07d:d表示打印整数,7表示数字的宽度,0表示用0填充空白位置.

检查这些链接以获取更多信息:
http://msdn.microsoft.com/en-us/library/56e442dc (v = VS.90).aspx [ http://msdn.microsoft.com/en-us/library/25366k66 (v = VS.90).aspx [



%07d : d means print integer, 7 specifies the width of the number, and 0 means that pad the empty places with 0.

Check these links for more information:
http://msdn.microsoft.com/en-us/library/56e442dc(v=VS.90).aspx[^]
http://msdn.microsoft.com/en-us/library/25366k66(v=VS.90).aspx[^]

-Saurabh


我认为您正在获取电话号码.
您为什么不尝试以下格式?
I think you are getting the number.
Why dont you try the below format?
int nCount  = 1;
sprintf(filename,"00000%d%s.%s",type,nCount,"PDF");


感谢回复.

我的IncNumber大小为6个字符000000.
如果我收到1位数/2位数/3位数...等(12/100)响应,则它对我不起作用.
根据响应号,如何更改文件名?

请帮帮我.
Thanks for reply.

My IncNumber size is 6 chars 000000.
If i receive 1 digit/2digit/3digit...etc (12/100) responses, then its not working for me.
Depending on response numbers, how can I do the file name change?

Help me out please.


这篇关于C文件名格式帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆