Ok this is confusing me but its probably a simple thing.
in the below code is a program that simulates the cat program.
Now why when running the program does it create a newline char even tho one is not put in when the printing of all the charecters in the file is compleate?
Code:
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char *argv[])
{
FILE *my_file;
char test; //charecter to test for EOF and printing.
if (argv[1] == NULL)
{
printf("Usage is mycat <text file> at this time there are no options\n");
return 0;
}
my_file = fopen(argv[1],"r");
if (my_file == NULL)
{
printf("Error opening file\n");
return 0;
}
do
{
test = fgetc(my_file);
if ( test != EOF)
printf("%c",test);
}
while( test != EOF);
fclose(my_file);
return 0;
}
the file test contains the following text
ok so no return in that line of txt "NOTE: when posting on the forem its adding line below the text but this isnt present in the actual file.
here is the program output
Code:
user@linux$ ./mycat test
cat cat cat mouse
user@linux$
user@linux$ cat test
cat cat cat mouse
user@linux$