The options for the 'cat' command are as follows:
-b Number the non-blank output lines, starting at 1. -e Display non-printing characters (see the -v option), and display a dollar sign (`$') at the end of each line. -n Number the output lines, starting at 1. -s Squeeze multiple adjacent empty lines, causing the output to be single spaced. -t Display non-printing characters (see the -v option), and display tab characters as `^I'. -u Disable output buffering. -v Display non-printing characters so they are visible. Control characters print as `^X' for control-X; the delete character (octal 0177) prints as `^?'. Non-ASCII characters (with the high bit set) are printed as `M-' (for meta) followed by the character for the low 7 bits.
#include 'stdlib.h'
#include 'stdio.h'
#include 'string.h'
#include 'unistd.h'
#define len 256;
/*function declarations*/
void non_blank (FILE *fin, FILE *fout, int writeLineNumbers);
void dollar_sign(FILE *fin, FILE *fout, int writeLineNumbers); //test comment
void output_line(FILE *fin, FILE *fout, int writeLineNumbers);
void squeeze (FILE *fin, FILE *fout, int writeLineNumbers);
void non_printing (FILE *fin, FILE *fout, int writeLineNumbers);
void non_printingvisible ((FILE *fin, FILE *fout, int writeLineNumbers);
int main(int argc, char *argv[])
{
int opt=0;
int bflag = 0;
int eflag = 0;
int nflag = 0;
int sflag = 0;
int tflag = 0;
int vflag = 0;
//Not sure what value is stored in opt?
while((opt=getopt(argc, argv, "benstv"))!=-1)
switch (opt)
{
case 'b':
bflag=1;
non_blank(stdin, stdout, opt);
break;
case 'e':
eflag=1;
dollar_sign(stdin, stdout, opt);
break;
case 'n': //test comment
nflag=1;
output_line(stdin, stdout, opt);
break;
case 's':
sflag=1;
squeeze(stdin, stdout, opt);
break;
case 't':
tflag=1;
non_printing(stdin, stdout, opt);
break;
case 'v':
vflag=1;
non_printingvisible(stdin, stdout, opt);
break;
default:
abort();
}
//test comment
//implementing -b functionality
void non_blank (FILE *fin, FILE *fout, int writeLineNumbers)
{
char line[len];
int linenumber=1;
while (fgets(line,len,fin))
{
if(writeLineNumbers)
printf("%d",linenumber);
if (fputs(line, fout)==EOF)
{ //test comment
printf(stderr,"Write to stdout failed.");
return;
}
if(line[0]!='\0')
++linenumber;
}
}
// implementing -e functionality.
void dollar_sign (FILE *fin, FILE *fout, int writeLineNumbers)
{
char line[len];
int linenumber=1;
while (fgets(line,len,fin)) //test comment
{
if(writeLineNumbers)
printf(" $");
if (fputs(line, fout)==EOF)
{
printf(stderr,"Write to stdout failed.");
return;
}
++linenumber;
}
}
//implementing -n functionality
void output_line (FILE *fin, FILE *fout, int writeLineNumbers)
{
char line[len];
int linenumber=1;
//test comment
while (fgets(line,len,fin))
{
if(writeLineNumbers)
printf("%d",linenumber);
if (fputs(line, fout)==EOF)
{
printf(stderr,"Write to stdout failed.");
return;
}
++linenumber;
}
}
/* void output_line (FILE *fin, FILE *fout, int writeLineNumbers)
{
char line[len];
int linenumber=1; //test comment
while (fgets(line,len,fin))
{
if(writeLineNumbers)
printf("%d",linenumber);
if (fputs(line, fout)==EOF)
{
printf(stderr,"Write to stdout failed.");
return;
}
++linenumber;
}
}
*/
//implementing -s functionality
void squeeze ( FILE *fin, FILE *fout, int writeLineNumbers)
{
char line[len] = {0};
// int linenumber=1;
//test comment
while (fgets(line,len,fin))
{
if(line[0]=='\n')
fin--=fin;
else if (fputs(line, fout)==EOF)
{
printf(stderr,"Write to stdout failed.");
return;
}
// ++linenumber;
}
}
//test comment
/*should converting each char to int (for ASCII value) and then printing back in char fix it? */
void non_printing ( FILE *fin, FILE *fout, int writeLineNumbers)
{
char line[len];
int linenumber= 1;
int i;
while (fgets(line,len,fin))
{
i=strlen(line); //test comment
for(i=0;i<strlen;i++) //test comment
line[i]
//test comment
if(line==NULL)
fin--;
if (fputs(line, fout)==EOF)
{
printf(stderr,"Write to stdout failed.");
return;
}
++linenumber;
}
}
main()
, as well as a level of indentation. \$\endgroup\$