Starting from:

$25

CSCI1730 - Breakout - Lab 05 - Solved

Basic I/O in C

For this assignment, you may use any C library functions to perform input and output.

Please first download the test cases (sample inputs) from eLC. Each of your programs should take a single command line argument representing the input file name, processes the input file, and writes to standard output.

Please note that the sample input files are plain text files created on odin. If you are to open them on a Windows machine, I would recommend special text editors designed for programmers (e.g., Notepad++) to avoid confusions on what the inputs actually look like.

Please note that in the sample outputs listed in this document, ‘\n’ is used to designate where newlines have been placed, not that the literal characters ‘\n’ should be written.

1           Problem / Exercise
•    You should create a folder on odin named LastName-FirstName-lab05 where LastName and FirstName are replaced with your last and first names, respectively.

•    You should place all the files you complete for this assignment inside this directory.

•    You must include a README file in this folder which includes:

–    Your name and UGA ID (811#).

–    Instructions for compiling and running your programs through the make utility.

•    For this lab you will complete three small programs as defined in the following sections. Please be sure the names of the executables are firstline, lastline, and longestline, respectively.

1.1         firstline.c
This program copies its input to output, up until the first newline character found, if present, if not it should print until the end of the input.

Test case
Expected Output
test1
this is\n
test2
this is\n
test3
a\n
test4
a\n
test5
\n
test6
asdf
test7
asdfqwerty\n
1

1.2         lastline.c
This program writes the last line of input given. This could potentially be an empty string.

Test case
Expected Output
test1
\n
test2
mondays\n
test3
asdfqwerty
test4
asdfqwerty\n
test5
asdfqwerty
test6
asdf
test7
hello
1.3         longestline.c
This program should write out the length of the longest line in the input (not including the newline characters which delimit a line). Please do print a newline character after printing the length.

Test case
Expected Output
test1
7\n
test2
7\n
test3
10\n
test4
10\n
test5
10\n
test6
4\n
test7
10\n

More products