I've been playing with Cygwin and C lately. I made this program to find new lines depending on what system they were created on.
Eventually, I'm wanting to create a converter to convert text files between POSIX and Windows.
Yes, I know one already exists but I want to try it myself.
Here's the code:
Code:
#include <stdio.h>
#include <stdint.h>
#include <string.h>
int main(int argc, char **argv) {
int8_t FileData;
uint8_t WinNewLine;
FILE *fp = NULL;
if(argc != 2) {
fprintf(stderr, "Enter one file.\n");
return 1;
}
fp = fopen(argv[1], "r");
if(fp == NULL) {
fprintf(stderr, "No file found.\n");
return 1;
}
FileData = getc(fp);
while(1) {
WinNewLine = 0;
if(FileData == '\r') {
FileData = getc(fp);
if(FileData == '\n') {
printf("Found a new line!\n");
WinNewLine = 1;
}
}
if(FileData == '\n' && WinNewLine == 0)
printf("Found POSIX new line!\n");
FileData = getc(fp);
if(feof (fp))
break;
}
return 0;
}