Hi I have been starting to learn a little bit about FILE-pointer and how to open a file,etc.. I'm reading the book C Primer Plus Fifth Edition by Stephen Prata ( SamsPublishing ) and I can't even get the solutions they have to work in my project.
This is how it looks
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int byte;
FILE * source;
int filect;
if (argc == 1)
{
printf("Usage: %s filename[s]\n", argv[0]);
exit(EXIT_FAILURE);
}
for (filect = 1; filect < argc; filect++)
{
if ((source = fopen(argv[filect], "r")) == NULL)
{
printf("Could not open file %s for input\n", argv[filect]);
continue;
}
while ((byte = getc(source)) != EOF)
{
putchar(byte);
}
if (fclose(source) != 0)
printf("Could not close file %s\n", argv[1]);
}
return 0;
}`
The output is:Usage:(Where my c project is located) filename[s] push down any key to continue... Why is this happening?