Part 2: C Input/Output
You should write a single program, part2.c, for all steps of this part. You should probably keep a working back-up each time you progress to a new step.
The steps become harder, with less hints, as you progress. If you are running out of time, don't try to complete all steps - instead get everything marked that you can by the deadline, and try to prepare better for the next lab exercise. (Ensure that you use submit to prove that you finished in time.)
Step 2A
Write a C program to read characters one-by-one from standard input (you can use ctrl-D to terminate the input), convert all upper-case characters to lower-case and all lower-case characters to upper-case, and write the result to standard output e.g.:
Hello World!
would become:
You should also count how many characters you have read, and how many of those you have converted in each direction, and output the totals at the end e.g.:
Read 13 characters in total, 8 converted to upper-case, 2 to lower-case

You will need to use getchar and putchar for the individual characters, as well as printf for the final character counts.
You may want to use some of the functions in ctype.h, such as tolower and isupper (e.g. use man ctype.h or look in Standard C).
Step 2B
Edit your program so that the input is read from a file opened from within your program. For the time being, you can use a fixed file-name such as "input".
Hint: Stream Manipulation
Remember to check that the file is correctly opened. Test this by running the program when there is no input file available.
Hint: refer to man fopen and SalaryAnalysis.c
Step 2C
Edit your program so that the output is written to a file, using a fixed file-name such as output.
Remember to check that the file is correctly opened. Test this by running the program when a file of that name exists, but is write protected e.g. chmod u-w output
Step 2D
Edit your program so that, instead of using fixed filenames such as "input" and "output", both file-names are read from standard input when the program is run (i.e. use scanf or similar; I don't want you to use command-line parameters).

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

#include <stdlib.h>
#include <stdio.h>

int main()
char c, fileName[20];
int count = 0, lower = 0, upper = 0;
FILE *fp, *op; //File pointers
printf("Please enter in the input file name: "); //Prompt
scanf("%s", fileName); //Read in string for fileName
fp = fopen(fileName, "r");...

By purchasing this solution you'll be able to access the following files:

for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats