proper.c
/* Placed in the Public Domain 5/25/97 John E. Carter */
/* Compiled under Turbo C 2.0 - should work under most PC C compilers */
/* */
/* does uppercase conversion on first character of line and first character */
/* after each space in the line. used with monocase database or mailing */
/* files to generate 'standard' name & address presentation. */
#include
#include
static char sccs_id[] = "@(#) proper.c - 1.2 - 03/05/93 (jec)";
main(argc,argv)
int argc;
char *argv[];
{
FILE *inf, *outf, *fopen();
char *p, *strchr(), *strrchr();
int c, i, j, siz, oldsiz, pos, creat(), prevchar;
char str[90], oldstr[90];
prevchar = siz = oldsiz = pos = c = i = j = 0;
for(i = 0;i < 90;i++)
{
str[i] = '\0';
oldstr[i] = '\0';
}
p = str;
if(argc < 3)
{
fprintf(stderr,"usage: proper \n");
exit(2);
}
if((inf = fopen(argv[argc - 2],"r")) == NULL)
{
printf("proper: can't open %s\n",argv[argc - 2]);
exit(2);
}
if((outf = fopen(argv[argc - 1],"w")) == NULL)
{
if((i = creat(argv[argc - 1],0666)) == NULL)
{
printf("proper: can't create %s\n",argv[argc - 1]);
exit(3);
}
else
{
close(i);
if((outf = fopen(argv[argc - 1],"w")) == NULL)
{
printf("proper: can't open %s\n",argv[argc - 1]);
exit(3);
}
}
}
while(! feof(inf))
{
strcpy(oldstr,str);
fgets(str,85,inf);
p = str;
siz = strlen(str);
oldsiz = strlen(oldstr);
if(siz == 1)
{
fprintf(outf,str);
continue;
}
if(strncmp(str,oldstr, siz >= oldsiz ? siz : oldsiz) == 0)
{
fclose(inf);
fclose(outf);
exit(0);
}
if(strncmp(str,"END",3) == 0)
{
printf("found 'END'\n");
fclose(inf);
fclose(outf);
exit(0);
}
*p = toupper(*p); /* first char of string */
for(;*p != '\n';) /* p++ */
{
prevchar = *p;
p++;
if(prevchar == ' ' || prevchar == '\t' || prevchar == '.' || prevchar == ',' || prevchar == ':' || prevchar == '(' || prevchar == '"' || prevchar == '\'')
{
*p = toupper(*p);
}
else
*p = tolower(*p);
}
fprintf(outf,"%s",str);
} /* end of while(! feof */
fclose(inf);
fclose(outf);
}
Home page
|
C Programs
Last update 21 Sep 2007. This page is proper.html
Copyright © 2002-2007 John E. Carter All Rights Reserved