*BSD News Article 97868


Return to BSD News archive

#! rnews 1513 bsd
Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!news.cs.su.oz.au!metro!metro!munnari.OZ.AU!spool.mu.edu!uwm.edu!vixen.cso.uiuc.edu!news-peer.sprintlink.net!news-pull.sprintlink.net!news-in-east.sprintlink.net!news.sprintlink.net!Sprint!207.43.3.4!gryphon.phoenix.net!not-for-mail
From: "Charles Tilbury" <ctilbury@infohwy.com.REMOVE.JUNK>
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Re: dos2unix
Date: 17 Jun 1997 02:05:13 GMT
Organization: C-Com/Phoenix Data Net (281) 486-8337/ http://www.phoenix.net
Lines: 39
Message-ID: <01bc7ac1$88ea1410$32327881@wingdog>
References: <339E506B.D46@slt.lk>
NNTP-Posting-Host: max3-192.infohwy.com
X-Newsreader: Microsoft Internet News 4.70.1161
Xref: euryale.cc.adfa.oz.au comp.unix.bsd.freebsd.misc:43032



Samath Wijesundera <samath@slt.lk> wrote in article
<339E506B.D46@slt.lk>...
> Dear FreeBSD Users,
> 
> Does anyone know if there is script or a utility to convert dos text
> files to unix format for BSD?
> 
> - Samath
> 

you could do this:

#include <stdio.h>
void main(int argc, char **argv) {
  FILE *infp, *outfp;
  int bytes_read;
  char buffer[1024];

  if((infp = fopen(argv[1], "rt")) == NULL) {
    perror("Cannot open infile:");
    return;
  }

  if((outfp = fopen(argv[2], "wb")) == NULL) {
    perror("Cannot open outfile:");
    return;
  }

  while(1) {
    if((bytes_read = fread(buffer, 1, 1024, infp)) != 0)
      fwrite(buffer, 1, bytes_read, outfp);
    else
      break;
  }
  fclose(infp);
  fclose(outfp);
}