C语言 [英] Increament number in C

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

问题描述


我创建了一个名为"Input.txt"的文件,其中包含2行,如
ABC123; 01/02/2008
PRQ456; 2004年4月23日
我写了LineParse函数.
这样,我就获得了该行的名字.使用该名称,我正在数据库中搜索各个文档.
这些文档按照命名约定< type>< inc no> .PDF"
检索并存储在一个文件夹中. 类型是:R/X/F,取决于文档类型.
公司编号:是我每次将文档存储在文件夹中时应增加1的数字.

除了"inc no",一切对我来说都很好.
到现在为止,我会根据得到的答复增加该数字.
对于第一个"ABC123",我收到2个响应,对于"PQR456",我收到4个响应,因此输出文件夹中应该总共有6个文档.

sprintf(Incnumber,%06d",iResponse +1); //需要更改逻辑
sprintf(Docfile,%s/%c%s.%s",Dir_Path,DType,Incnumber,"PDF");

但是我的inc no不会被前2个文档覆盖,因此我在输出文件夹中仅收到4个文档,分别为r000001.PDF,r000002.PDF,r000003.PDF,r000004.PDF.
由于r000001.PDF和r000002.PDF每次都被覆盖.

帮帮我.
在此先感谢您.

Hi,
I had created a file called "Input.txt" which contains 2 lines as
ABC123;01/02/2008
PRQ456;04/23/2004
I had written LineParse function.
In that I am getting the first name in the line. Using that name I am searching respective documents in DB.
These documents retrived and stroed in one folder with naming convention as "<type><inc no>.PDF"
Where type is : R/X/F depending on document type.
Inc no: is the number which should increment by 1 each time I am storing document in folder.

Everything is working fine for me except "inc no".
Till now I am incrementing that number depending on responses I got.
For first "ABC123" I got 2 responses and for "PQR456" I am receiving 4 responses, so total 6 documents should be available in output folder.

sprintf(Incnumber,"%06d", iResponse + 1); // need to change the logic
sprintf(Docfile,"%s/%c%s.%s",Dir_Path,DType,Incnumber,"PDF");

But my inc no is overrided for first 2 docs, hence I am receiving only 4 docs in output folder as r000001.PDF, r000002.PDF, r000003.PDF, r000004.PDF.
As r000001.PDF and r000002.PDF is getting override each time.

Help me out.
Thanks in advance.

推荐答案

没有看到其他代码,我的猜测是您为解析的每一行重置了增量计数器.

欢呼声
Without seeing additional code, my guess is that you reset your increment counter for every line you parse.

Cheers


您只需要为响应维护一个累积计数器,例如:

You just need to maintain a cumulative counter for the responses, for instance:

iTotalResponses += iResponse;
sprintf(Incnumber,"%06d", iTotalResponses + 1); 
sprintf(Docfile,"%s/%c%s %s",Dir_Path,DType,Incnumber,"PDF");



:)



:)


感谢回复.

我已经使用iResponse调用了ExtractDoc()函数.
因此,对于第一行解析,我得到iResponse = 0,然后iResponse =1.
对于第二行解析,我得到iResponse = 0然后= 1然后= 2然后= 4等....

因此,每当我增加Incnumber时,
sprintf(Incnumber,%06d",iResponse +1);
对于iResponse 0和1,将覆盖文档名称.

预先感谢
Thanks for reply.

I had called a ExtractDoc() function with iResponse.
So for first line parse i get iResponse = 0 and then iResponse =1.
For second line parse i get iResponse=0 then =1 then =2 then =4 etc....

So whenever I increment Incnumber,
sprintf(Incnumber,"%06d", iResponse + 1);
for iResponse 0 and 1 , document name gets override.

Thanks in advance


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

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