C C-Program : Very simple UNIX to DOS in C (textfile)

Hello,

Would you know a very tiny, small, portable, .... C-Program for a very simple UNIX to DOS in C (textfile).

It should operate like : unix2dos file.txt

and it will give a DOS file (textfile.)

Thank you in advance!
 

I know this one but I would expect a C code.
example using C but here it does not ouptut to display but to file.
Code:
// copy

#include <stdio.h>
#include <stdlib.h>

int main( int argc, char *argv[])
{

   FILE *source, *target; int ch ;
   source = fopen( argv[ 1 ], "r");
   if( source == NULL )
   {
      printf("Press any key to exit...\n");
      exit(EXIT_FAILURE);
   }

   target = fopen( argv[ 2 ] , "ab");
   if( target == NULL )
   {
      fclose(source);
      printf("Press any key to exit...\n");
      exit(EXIT_FAILURE);
   }

   printf("Source: %s\n",  argv[ 1 ] );
   printf("Target: %s\n",  argv[ 2 ] );
   printf("Cat...\n");

   while( ( ch = fgetc(source) ) != EOF )
   {
         fputc(ch, target);
   }

   printf("File copied successfully.\n");
   fclose(source);
   fclose(target);
   return 0;
}
 
Would you know a very tiny, small, portable, .... C-Program for a very simple UNIX to DOS in C (textfile).

The smallest thing I can imagine doing this, perhaps, is:
C:
#include <stdio.h>
int main() {
  int c;
  while( (c=getchar()) != EOF )  {
    if (c == '\n') putchar('\r');
    putchar(c);
  }
  return 0;
}
Then you do something like:
cat textfile_lines_with_LF | ./(the_little_marvel_above) > textfile_lines_with_CRLF
 
Back
Top