How to add a carriage return when write to text file? - VxWorks

This is a discussion on How to add a carriage return when write to text file? - VxWorks ; Hi guys, I am trying to write my output to a file. This is what I have so far: char path[256]; sprintf(path,"/example.txt"); if((fd=open(path, O_RDWR, 0))==ERROR) { printf("Error opening file %#x\n",errno); close(fd); } while (bytesPrinted { sprintf (path, "%s \n", OutLine); ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: How to add a carriage return when write to text file?

  1. How to add a carriage return when write to text file?

    Hi guys,

    I am trying to write my output to a file. This is what I have so far:

    char path[256];
    sprintf(path,"/example.txt");

    if((fd=open(path, O_RDWR, 0))==ERROR)
    {
    printf("Error opening file %#x\n",errno);
    close(fd);
    }

    while (bytesPrinted < bytesNeeded)
    {
    sprintf (path, "%s \n", OutLine);
    write (fd, path, 56);
    }
    close (fd);

    I can't get OutLine to write to a new line everytime...The strings are
    all concatinated on one line in example.txt. How can I add a carriage
    return in the code so each line will be written to a new line?

    Thanks for your help,
    Binh



  2. Re: How to add a carriage return when write to text file?

    On Mar 19, 4:19*pm, Binhminhmatt...@gmail.com wrote:
    > Hi guys,
    >
    > I am trying to write my output to a file. *This is what I have so far:
    >
    > char path[256];
    > sprintf(path,"/example.txt");
    >
    > if((fd=open(path, O_RDWR, 0))==ERROR)
    > {
    > * * * printf("Error opening file %#x\n",errno);
    > * * *close(fd);
    > *}
    >
    > while (bytesPrinted < bytesNeeded)
    > {
    > * * * * * sprintf (path, "%s \n", OutLine);
    > * * * * * write (fd, path, 56);}
    >
    > close (fd);
    >
    > I can't get OutLine to write to a new line everytime...The strings are
    > all concatinated on one line in example.txt. *How can I add a carriage
    > return in the code so each line will be written to a new line?
    >
    > Thanks for your help,
    > Binh


    Oh, I got it, use
    sprintf (path, "%s \r\n", OutLine);

  3. Re: How to add a carriage return when write to text file?

    windows .txt format use \r\n as new line, so you may try this instead of \n.

    ????
    news:8c830865-6d3c-4513-b09f-214e76f41350@m44g2000hsc.googlegroups.com...
    > Hi guys,
    >
    > I am trying to write my output to a file. This is what I have so far:
    >
    > char path[256];
    > sprintf(path,"/example.txt");
    >
    > if((fd=open(path, O_RDWR, 0))==ERROR)
    > {
    > printf("Error opening file %#x\n",errno);
    > close(fd);
    > }
    >
    > while (bytesPrinted < bytesNeeded)
    > {
    > sprintf (path, "%s \n", OutLine);
    > write (fd, path, 56);
    > }
    > close (fd);
    >
    > I can't get OutLine to write to a new line everytime...The strings are
    > all concatinated on one line in example.txt. How can I add a carriage
    > return in the code so each line will be written to a new line?
    >
    > Thanks for your help,
    > Binh
    >
    >


+ Reply to Thread