Stripping leading 0s off a text file.

Hi
Im a delphi programmer not C++ hense I need some help if possible. I have a text file called Input.txt which is laid out as so

<Char 14>,<Char 4>

ie 01234567899999,1999

I need to cycle through this file and spit out  a new file called outfile.txt with all the information minus the leading zeros.

ie if Input.txt was as follows

01111111111111,9999
00000333333333,0099

The output file would be

1111111111111,9999
333333333,0099

I am using Borlands C++ 5.02 and running this program in DOS.

Thanks for any help..
Stu
StuartB_99Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
#include <stdio.h>

#define BUF_MAX 256 // use a reasonable value here...
chat acBuf [ BUF_MAX];
char* pc;
FILE* pIn;
FILE* pOut;

pIn = fopen ( "in.txt", "r");
pOut = fopen ( "out.txt", "w");

while ( fgets ( acBuf, BUF_MAX, pIn))
{
 pc = acBuf;

 while ( *pc == '0') pc++;

 fputs ( pc, pOut);
}

Error checking omitted for brevity ;-)

Feel free to ask if you encounter problems!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jkrCommented:
Opps, I forgot 2 lines that should be at the end of the above code:

fclose ( pIn);
fclose ( pOut);

Sorry...
0
StuartB_99Author Commented:
Thanx jkr,
Im getting a declaration syntax error at the

chat acBuf [ BUF_MAX];

line


any ideas,

Stuart
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

StuartB_99Author Commented:
Thanx jkr,
Im getting a declaration syntax error at the

chat acBuf [ BUF_MAX];

line


any ideas,

Stuart
0
jkrCommented:
Sorry, typo:

chat acBuf [ BUF_MAX];

should of course read

char acBuf [ BUF_MAX];
0
StuartB_99Author Commented:
Excellent thanks,
However Im now getting

cannot convert 'char_ss_*' to 'char'

at

>>    pc = acBuf;

sorry to be a neusense, but I havent got a clue with C++ just Delphi..

Thanks

Stu
0
StuartB_99Author Commented:
Some more cash for your efforts jkr.....!!!!!
0
jasonclarkeCommented:
the declaration of pc should probably be:

char pc

if you plan to do this sort of stuff a lot, you could try getting perl, it makes this sort of thing much easier! The following is a complete perl program to achieve the same thing:

while (<>)
{
   s/^0+(.*)$/$1/;
   print "$_";
}
0
jasonclarkeCommented:
Ignore what I said about char pc, it is incorrect.  (Teach me to read the code better!).

The code looks alright, make sure you have:

    char *pc;

and NOT just:

    char pc;
0
StuartB_99Author Commented:
Thanks very much,

Job done..

You have saved the world (OK slight exageration maybe!!)
I realy appreciate it, is Pearl obtainable as a free download to try it out do you know??
0
jasonclarkeCommented:
perl is available for free from:
 
http://www.activestate.com/ActivePerl/
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.