Skip to content

Instantly share code, notes, and snippets.

@DreamVB
Created August 5, 2016 21:17
Show Gist options
  • Select an option

  • Save DreamVB/fb9f92a255e71f5fc19658c084393ddd to your computer and use it in GitHub Desktop.

Select an option

Save DreamVB/fb9f92a255e71f5fc19658c084393ddd to your computer and use it in GitHub Desktop.
Convert dos line breaks to unix
/*
dos2unix By DreamVB
Version 1.0
Program to convert dos line endings to unix \n
Please feel free to to use as you like.
Please let me know if you found this code usfull e. dreamvb@outlook.com
*/
#include <stdio.h>
#include <string>
int main(int argc, char* argv[]){
FILE *fin = NULL;
FILE *fout = NULL;
char c = '\0';
char d = '\0';
if(argc < 3){
printf("Usage: <InFile> <OutFile>\n");
return 0;
}
//Open inputfile.
fin = fopen(argv[1],"rb");
//Try and see if inputfile opened.
if(fin == NULL){
printf("IO/Error cannot open file\n");
return 0;
}
//Open output file
fout = fopen(argv[2],"wb");
//See if output file opened.
if(!fout){
printf("IO/Error cannot write file\n");
return 0;
}
while(!feof(fin)){
c = fgetc(fin);
if(c != EOF){
//Check for cr
if(c == '\r'){
continue;
//Get next
fputc(c,fout);
}else{
fputc(c,fout);
}
}
}
//Close files
fclose(fin);
fclose(fout);
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment