How to jump to next line when writing to a File.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to jump to next line when writing to a File.

Jump to solution
1,877 Views
JaimeR
Contributor III

Hi, I am writing to a file (.TXT) in a USB flash memory. I can write to the file, however, I dont know how to jump to next line. I have tried this:

 

 

 i = sprintf(buf,"%d-%d-%d  %d:%d  Puerta %d \n",dia, mes, year, hora, minuto, puerta);
  write(fd, buf, i);

 

and some other ways with the same outcome. The outcome is the file with the information I want to write but instead of jumping to next line, a little square appears as the \n.

 

Anyone knows why is this happening or knows how to jump to next line?

 

Thanks in advance.

0 Kudos
1 Solution
774 Views
eGuy
Contributor IV

You  can try these:

1) use "\r\n" instead of only "\n"

 

2) use different application (notepad, wordpad, or visual studio etc) to open the result .txt file

   ( some applications need to be configured to show \n as New-Line)

 

Regards,

 

 

Message Edited by eGuy on 2009-06-23 01:25 PM

View solution in original post

0 Kudos
3 Replies
775 Views
eGuy
Contributor IV

You  can try these:

1) use "\r\n" instead of only "\n"

 

2) use different application (notepad, wordpad, or visual studio etc) to open the result .txt file

   ( some applications need to be configured to show \n as New-Line)

 

Regards,

 

 

Message Edited by eGuy on 2009-06-23 01:25 PM
0 Kudos
774 Views
JaimeR
Contributor III

I used \n only and open the file with Microsoft Excel since I am using a .CSV file. It jump to next line using \n . When it didnt work I was only testing with notepad.

Message Edited by Jaime R on 2009-06-24 03:25 PM
0 Kudos
774 Views
CarlFST60L
Senior Contributor II

Also note that there is a flag that can automatically append line ends with line feeds for your stream (I think its in config.h). stdout has this flag set by default in all the MQX releases, the other two comm's ports do not have this flag set. You can also set this flag using ioctl.

Message Edited by CarlFST60L on 2009-06-24 11:43 PM
0 Kudos