add GenerateLineEndings.c

This commit is contained in:
SileNce5k 2023-06-24 21:26:28 +02:00
parent f97246b6cc
commit 4c4ad2cd9c
No known key found for this signature in database
GPG key ID: C507260E7F2583AD

52
GenerateLineEndings.c Normal file
View file

@ -0,0 +1,52 @@
#include <stdio.h>
int main() {
// Generate LF line endings
FILE* file_lf = fopen("file_lf.txt", "w");
if (file_lf == NULL) {
printf("Error creating file with LF line endings.\n");
return 1;
}
for (int i = 1; i <= 10; i++) {
fprintf(file_lf, "Line %d\n", i);
}
fclose(file_lf);
// Generate CRLF line endings
FILE* file_crlf = fopen("file_crlf.txt", "w");
if (file_crlf == NULL) {
printf("Error creating file with CRLF line endings.\n");
return 1;
}
for (int i = 1; i <= 10; i++) {
fprintf(file_crlf, "Line %d\r\n", i);
}
fclose(file_crlf);
// Generate mixed line endings
FILE* file_mixed = fopen("file_mixed.txt", "w");
if (file_mixed == NULL) {
printf("Error creating file with mixed line endings.\n");
return 1;
}
for (int i = 1; i <= 10; i++) {
if (i % 2 == 0) {
fprintf(file_mixed, "Line %d\r\n", i);
} else {
fprintf(file_mixed, "Line %d\n", i);
}
}
fclose(file_mixed);
printf("Files generated successfully.\n");
return 0;
}