
read a file than produce 2 output files(HELP)
Quote:
> I have to write a program that reads a file that contains names. The program
> must read all names until the end of file. Then it has to produce one file
> that puts all users names in upper case and a second file that puts all
> users names in lower case. Blank lines in the input file should not be
> written to the output file.
> need some help
I don't usually help people with their homework, but give this a shot.
a.out inputfilename
to run. Output is stored in lc.txt (lowercase) and uc.txt (uppercase).
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
FILE *fO=NULL,*f0=NULL,*fo=NULL;
char buf[512];
int Q,O;
if(argc>1)fO=fopen(argv[1],"r");
else putc("a.out inputfile - to run");
f0=fopen("uc.txt","w");
fo=fopen("lc.txt","w");
if(!fO||!f0||!fo) return EXIT_FAILURE;
while(fgets(buf,511,fO)!=NULL){
if(1<(Q=strlen(buf))){
for(O=0;O<Q;O++){
(O[buf]>64&&O[buf]<91)?fputc((int)(O[buf])+32,fo)
:fputc((int)O[buf],fo);
(O[buf]>96&&O[buf]<123)?fputc((int)(O[buf])-32,f0)
:fputc((int)O[buf],f0);
}
}
}
return EXIT_SUCCESS;
Quote:
}
--
--