PADDER.C Tony Lawrence:
A simple C program that pads text files to fixed length records. Was at one time very useful; is probably not today, but who knows?
I wrote this because I needed to bring some files into Filepro as fixed length fields.
It was written on Microsoft DOS, but will compile on Linux (though not on OS X - missing "fcloseall").
Usage: PADDER INFILE OUTFILE PAD-SIZE
#include <stdio.h> #include <string.h> char big_buff[1024]; main(argc,argv) int argc; char **argv; { char *bb=big_buff; FILE *ipf,*opf; int width=100; int warning=0; int maxwidth=0; int line=0; if (argc < 3) help(argv[0]); if (argc == 4) width=atoi(argv[3]); if (width < 1) width=100; if ((ipf=fopen(argv[1],"r"))==NULL) { fprintf(stderr,"Can't open %s for input\n",argv[1]); help(argv[0]); } if ((opf=fopen(argv[2],"w"))==NULL) { fprintf(stderr,"Can't open %s for output\n",argv[1]); help(argv[0]); } while (fgets(bb,1024,ipf)) { char *tp; int mwidth; line++; if (tp=strchr(bb,'\n')) *tp=0; if ((mwidth=strlen(bb)) > width ) { if (++warning == 1) fprintf(stderr,"\007Warning: Input width exceeds %d\n",width); fprintf(stderr,"Input line %5d , truncated %3d chars:\n %s\n",line,mwidth-width,bb+width); if (mwidth > maxwidth) maxwidth=mwidth; } fprintf(opf,"%-*.*s\n",width,width,bb); } fcloseall(); if (maxwidth) fprintf(stderr,"(Max input width was %d)\n",maxwidth); exit(0); } help(name) char *name; { fprintf(stderr,"Usage:\n%s input-file output-file [pad-size]\n",name); fprintf(stderr,"[pad-size] defaults to 100\n"); exit(1); }
Got something to add? Send me email.
(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Printer Friendly Version
-> -> Dos Programs: C code to pad text files to fixed length records.
Increase ad revenue 50-250% with Ezoic
Inexpensive and informative Apple related e-books:
El Capitan: A Take Control Crash Course
Sierra: A Take Control Crash Course
Take Control of Apple Mail, Third Edition
iOS 8: A Take Control Crash Course
Take Control of Parallels Desktop 12
More Articles by Tony Lawrence
Find me on Google+
© 2011-04-25 Tony Lawrence
Printer Friendly Version
Pads text files to fixed length records Copyright © January 1997 Tony Lawrence
Have you tried Searching this site?
Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates
This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.
Contact us
Printer Friendly Version