then it has to be printed to the screen 80 chars per line.
this is done in c.
My coding is super weak and don't know where to begin.
Any help is appreciated
then it has to be printed to the screen 80 chars per line.
this is done in c.
My coding is super weak and don't know where to begin.
Any help is appreciated
given the requirement of change upper case to lower case, will need:
#include <ctype.h>
for the tolower()
function and isalnum()
function
............
to input the characters from the file, and since each char needs to be processed, will need:
#include <stdio.h>
for the function: getchar()
and for the definition of EOF
and for the function: putc()
.............
To count the number of characters currently displayed on the current line, will need:
size_t lineLen = 0;
................
to know when to go to the next output line will need that number 80
#define MAX_LINE_LEN (80)
.........
If the command line contains:
myprogram < inputFile.txt
then will not need to open/close the file within the program.
...........
naturally, will need a main()
function with no parameters:
int main( void )
{
...
} // end function: main
.........
Since we will be reading a lot of characters, one at a time, will need:
The following while()
statement edited so can handle any input char.
int ch;
while( (ch = getchar()) != EOF )
{
...
}
........
Since only displaying printable characters, will need a line like:
if( isalnum( ch ) )
}
....
}
..........
Since displaying only in lower case will need a line like:
ch = tolower( ch );
............
need to actually output the char, and track the length of the line
putc( ch );
lineLen++;
............
need to output a new line after 80 chars and reset counter
if( MAX_LINE_LEN >= lineLen )
{
lineLen = 0;
putc( '\n' );
}
............
After the EOF
is encountered, will need to output a final newline so all characters are displayed
putc( '\n' );
............
That is really all there is to it.