I have a code snippet below. On macOS, I have run it in Xcode and CLion with the same odd result. On the other hand, on Linux when compiled with gcc it runs flawlessly. I would like to know whether the code at any point produces undefined behaviour. The input file it tries to parse is the vigenére table, you know, 26-character rows with the latin alphabet, and the letters are shifted left by 1 on the 1 lower row. Every line is terminated by CRLF. The expected output is the table printed out on the console. The unexpected part is that az least 1 line is displayed incorrectyl on macOS. Here’s the input btw: https://pastebin.com/QnucTAFs (I dont know however, whether the corresponding line endings got preserved)
#include <stdio.h>
#include <stdlib.h>
char ** parse(char *path) {
FILE *f = fopen(path, "r");
char **table = (char**)malloc(sizeof(char*) * 26);
int i = -1;
do table[++i] = (char*)malloc(sizeof(char) * 27);
while (fscanf(f, "%s", table[i]) > 0);
return table;
}
int main() {
char **table = parse("Vtabla.dat");
for (int i = 0; i < 26; i++) {
for (int x = 0; x < 26; x++)
printf("%c", table[i][x]);
printf("\n");
}
return 0;
}