I am trying to write a program that reads a text file into a buffer (that has max size of 1024 bytes). Then the program will print out the entire file on the command line. It is a primitive program that I am writing to learn more about C. I can understand C code but I have never written anything useful so I'm taking baby-steps to get to the point where I ultimately have a useful program.
My problem is that I am having problems with the various types that deal with the simplest operation within C. I tried to open a file with "FILE filetoprint = fopen(argv, 'r');" but I got this error " In function ‘main’:
here is my code:
You guys got some suggestions?
My problem is that I am having problems with the various types that deal with the simplest operation within C. I tried to open a file with "FILE filetoprint = fopen(argv, 'r');" but I got this error " In function ‘main’:
Code:
openandprint.c:16: warning: passing argument 1 of ‘fopen’ from incompatible pointer type
/usr/include/stdio.h:249: note: expected ‘const char * __restrict__’ but argument is of type ‘char **’
openandprint.c:16: warning: passing argument 2 of ‘fopen’ makes pointer from integer without a cast
/usr/include/stdio.h:249: note: expected ‘const char * __restrict__’ but argument is of type ‘int’
openandprint.c:16: error: invalid initializer
here is my code:
Code:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
// fopen(*argv[]);
int argsoncline = 0;
printf("\n");
for(argsoncline; argsoncline < argc; argsoncline++)
if (argsoncline > 0)
printf("%s ", argv[argsoncline]);
printf("\n\n");
//const char* justreadfile = {"r"};
FILE filetoprint = fopen(argv, 'r');
//check if file open was successful
//if (Filetoprint < 0 )
// printf("file open failure");
return(0);
}
You guys got some suggestions?