#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    2
    Rep Power
    0

    Confused about TXT file line-feed


    I'm wanting to make a txt file, using C, and written to an SD card, consisting of a single long column.
    The character I'm writing to that column is defined here:
    data_str[0]= ','; //comma delineator
    data_str[1]= a + '0';
    data_str[2]= b + '0';
    data_str[3]= c + '0';
    data_str[4]= '\\' ;
    data_str[5]= 'r'; //carriage return
    data_str[6]= '\\';
    data_str[7]= 'n'; // line feed

    a comma delineator followed by three BCD digits followed by a "carriage return" and a "line feed"
    then I do:
    FSfwrite (data_str, 1, 8, pointer);
    which creates a TXT file on the SD card looking like this:

    ,309\r\n,327\r\n,327\r\n,310\r\n,333\r\n,327\r\n,317\r\n,341\r\n,329\r\n,326\r\n,348\r\n,330\r\n,331 \r\n,345\r\n,322\r\n,328\r\n ... and so on

    when what I wanted was this

    ,309
    ,327
    ,327
    ,310
    ,333
    ,327

    and so on.

    obviously the text reader (Windows notepad) is not responding to the \r\n command - it's simply printing it out.
    What am I doing wrong please?
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,417
    Rep Power
    1871
    Try
    Code:
    data_str[4]= '\r' ;
    data_str[5]= '\n';
    and write 6 bytes instead of 8.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    2
    Rep Power
    0
    Thank you Salem! It works perfectly now.
    Rick

IMN logo majestic logo threadwatch logo seochat tools logo