Hey everyone,
Taken the following code; is there a "proper" or dynamic way to
allocate the length of line[]?
#include <stdio.h>
#include <errno.h>
int main(int argc, char **argv) {
FILE *fp;
char line[4096];
if(argc < 2) {
printf("usage: %s <file>\n", argv[0]);
return(1);
}
if((fp = fopen(argv[1], "r")) == NULL) {
perror("fopen") ;
return(1);
}
while(fgets(lin e, sizeof(line), fp)) {
printf("%s", line);
}
return(0);
}
Taken the following code; is there a "proper" or dynamic way to
allocate the length of line[]?
#include <stdio.h>
#include <errno.h>
int main(int argc, char **argv) {
FILE *fp;
char line[4096];
if(argc < 2) {
printf("usage: %s <file>\n", argv[0]);
return(1);
}
if((fp = fopen(argv[1], "r")) == NULL) {
perror("fopen") ;
return(1);
}
while(fgets(lin e, sizeof(line), fp)) {
printf("%s", line);
}
return(0);
}
Comment