B
bwaichu
I have written the program below to just create and populate an html
file. I am running into a problem when viewing the created file in vi.
I am told by vi that the file does not have an end of line.
Here's the code:
int
main(int argc, char **argv) {
FILE *fd;
int x;
char buff[8196];
x = 0;
bzero(buff, sizeof(buff));
(void)strlcpy(buff,"<HTML>", sizeof(buff));
while (x < 1024) {
(void)strlcat(buff,"A",sizeof(buff));
x++;
}
(void)strlcat(buff, "</HTML>", sizeof(buff));
fd = fopen("test5.html", "w+");
if (fd == NULL)
errx(-1, "failed to open");
(void)fprintf(fd, "%s", buff);
(void)fclose(fd);
exit(EXIT_SUCCESS);
}
Now, vi will not warn about noeol if I change this line:
(void)fprintf(fd, "%s", buff);
to
(void)fprintf(fd, "%s\n", buff);
Where I am confused is that I thought streams automatically terminated
the file with an CR (0a) in a unix environment. What bothers me is
that the above would in theory make the code less portable. Am I
overlooking something?
file. I am running into a problem when viewing the created file in vi.
I am told by vi that the file does not have an end of line.
Here's the code:
int
main(int argc, char **argv) {
FILE *fd;
int x;
char buff[8196];
x = 0;
bzero(buff, sizeof(buff));
(void)strlcpy(buff,"<HTML>", sizeof(buff));
while (x < 1024) {
(void)strlcat(buff,"A",sizeof(buff));
x++;
}
(void)strlcat(buff, "</HTML>", sizeof(buff));
fd = fopen("test5.html", "w+");
if (fd == NULL)
errx(-1, "failed to open");
(void)fprintf(fd, "%s", buff);
(void)fclose(fd);
exit(EXIT_SUCCESS);
}
Now, vi will not warn about noeol if I change this line:
(void)fprintf(fd, "%s", buff);
to
(void)fprintf(fd, "%s\n", buff);
Where I am confused is that I thought streams automatically terminated
the file with an CR (0a) in a unix environment. What bothers me is
that the above would in theory make the code less portable. Am I
overlooking something?