I'm currently trying to create a code in Cygwin using pure C to display ASCII control characters that may be present in the text file in a ASCII control characters non-printable form.
I can call to a text file to display its contents but in normal ASCII characters but I cannot figure out how to display NON-printable characters from the text file if anyone can tell what I need to do please.
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
char ch;
FILE *data;
char fname[100];
if (argv[1]!=NULL)
{
strcpy(fname, argv[1]);
while(access(fname, F_OK) !=0)
{
perror("Error");
printf("\nspecify correct file to display\n");
gets(fname);
}
}
else if (argv[1]==NULL)
{
strcpy(fname, argv[1]);
while(access(fname, F_OK) !=0)
{
perror("Error");
printf("\nspecify correct file to display\n");
gets(fname);
}
}
data = fopen (fname, "r");
ch = fgetc(data);
while( ch != EOF)
{
putchar(ch);
ch = getc(data);
}
fclose(data);
return (EXIT_SUCCESS);
}