Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_COL 70
#define MAX_ROW 20
int main(void) {
FILE *fp;
char *text;
char line[MAX_COL];
int i;
fp = fopen("input.txt", "r");
if (fp == NULL) {
fprintf(stderr, "!!! Failed to open file\n");
abort();
}
text = malloc(MAX_COL*MAX_ROW*sizeof(char));
for (i=0; i<MAX_ROW; i++) {
if ((fgets(line, MAX_COL, fp)) != NULL)
strcat(text, line);
}
printf("%s", text);
return EXIT_SUCCESS;
}
With my input.txt file being
And in particular, there is no new line after the letter h, but when I print out the text string, I get a new line after h. Why is this?