I recently updated an older program of mine to create a linux shell file as well as a dos bat file.
I deal with both linux and windows systems using a common program between the two platforms. The program is called via a batch file or shell script, and to keep life simple I wrote a program in C to generate the equivalent script for each platform.
In the end to get things to work on the linux side of the house I need run dos2unix on the resulting file to convert the cr\lf to just cr.
What Im trying to do is find a way to force Pelles C to just generate the cr ...
Originally I had
if ((shtarget = fopen(cScriptType, "w")) == NULL)
and
fprintf(shtarget, "#####\n", NULL);
I changed that to
if ((shtarget = fopen(cScriptType, "wb")) == NULL)
and
fprintf(shtarget, "#####\xD", NULL);
The end result looks promising, ie notepad is a mess but it looks right in wordpad, but linux is still thinking its a cr / lf file.
Im still using 4.5x, I hate upgrading things that still work but I can and will upgrade if needed.
RSRC0009.DLL: Version 4.50.1
SUPPORT.DLL: Version 4.50.4
POCFMT.DLL: Version 4.50.3
PORC.DLL: Version 4.50.1
POBR.DLL: Version 4.50.2
POBR.EXE: Version 4.50.2
IDESPAWN.EXE: Version 4.50.1
POCC.EXE: Version 4.50.15
POLINK.EXE: Version 4.50.2
Thanks
Yes, you need the 'binary' mode (wb) for this to work - in 'text' mode (w) any LF will be converted to CR+LF. AFAIK, Linux only wants LF, and this was exactly what I got when I tried this in 4.50 (CR is for 'appletosh'):
#include <stdio.h>
int main(void)
{
FILE *f;
if ((f = fopen("myfile.txt", "wb")) != NULL)
{
fprintf(f, "aaaaa\n");
fprintf(f, "bbbbb\n");
fprintf(f, "ccccc\n");
fclose(f);
}
return 0;
}
Bingo ..
Switching back from \xD to \n and opening in binary mode did the trick.