read a file than produce 2 output files(HELP) 
Author Message
 read a file than produce 2 output files(HELP)

read a file than produce 2 output files(HELP)
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

--



Thu, 30 Aug 2001 03:00:00 GMT  
 read a file than produce 2 output files(HELP)
Please post some code. No one is going to assist you without seeing your
code (a sign of a serious request for help).

--

Paul Lutus
www.arachnoid.com

<snip>

--



Fri, 31 Aug 2001 03:00:00 GMT  
 read a file than produce 2 output files(HELP)

says...

Quote:
> read a file than produce 2 output files(HELP)
> 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.

fgets will allow you to read in lines from a file.
toupper will convert characters to upper-case.
tolower will convert characters to lower-case.

You open files with fopen, and will probably want to write the lines
out with fputs.

You can test for a line being blank with a small loop that looks
through all the characters read in for the line, and using isspace on
each to find whether there's at least one character that's not
whitespace.  If they're all whitespace, simply read in another line.

I'm afraid I'm not going to tell you much more than that -- this
sounds a bit too much like homework for me to be comfortable writing
the code for you, even though it would have been easier (and shorter)
than writing this post.

--



Fri, 31 Aug 2001 03:00:00 GMT  
 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:
}

--

--



Fri, 31 Aug 2001 03:00:00 GMT  
 read a file than produce 2 output files(HELP)

Quote:

>  else putc("a.out inputfile - to run");

should be puts() - sorry.

--

--



Sat, 01 Sep 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. read a file than produce 2 output files(HELP)

2. Reading a file & output a file

3. Please Help: Reading & Writing from/to a Unicode File produces garbage in output file

4. Help! reading from a file and output

5. reading output produced by an archive

6. reading output (stdout) produced by an archive

7. Problem producing rtf file for help project

8. fgets reading a configuration file: compiles OK but output wrong

9. Read command output file

10. Read and Output RTF file

11. Sorting output to diff files into a single file

12. output file as true 3-d file

 

 
Powered by phpBB® Forum Software