linefeed

Serial port binary transfer changes carriage return

偶尔善良 提交于 2019-12-18 16:40:31
问题 I have been trying to implement a primitive serial file transfer protocol in C this past week and I've come across a really weird problem which I can't seem to find the solution for online. I've managed to transfer binary data over the serial port and receive it but in the process, all the "0D" bytes are converted to "0A". The following is my code. #include <stdlib.h> #include <stdio.h> /* Standard input/output definitions */ #include <string.h> /* String function definitions */ #include

Echo text with Unix line endings from a Windows batch (.bat) script

点点圈 提交于 2019-12-17 23:29:19
问题 Say I have the following batch script: For ... DO ( SET VAL=%%B IF defined VAL echo %%A=%%B >> %OUTPUT_FILEPATH% ) How could I get the echo to output using Unix (just line feed) line endings? Alternatively, could I write the file as-is then convert it from the batch script afterwards? (some kind of find /r/n and replace with /n? If so, how would I do that?) I'd like a self-contained solution (i.e. one that doesn't involve downloading extra utilities, and can be done from within the batch

Setting Java VM line.separator

廉价感情. 提交于 2019-12-17 09:50:25
问题 Has anybody found a way how to specify the Java line.separator property on VM startup? I was thinking of something like this: java -Dline.separator="\n" But this doesn't interprete the "\n" as linefeed character. Any ideas? 回答1: Try using java -Dline.separator=$'\n' . That should do the trick, at least in bash. Here is a test-run: aioobe@r60:~/tmp$ cat Test.java public class Test { public static void main(String[] args) { System.out.println("\"" + System.getProperty("line.separator") + "\"");

\n and \r seem to work everywhere. Why is line.separator more portable?

情到浓时终转凉″ 提交于 2019-12-14 00:47:56
问题 I was just perusing through questions, and I found System.getProperty(line.separator) used in place of \n with the author's comment that the code was "portable". Reading through various forums, I've seen two groups: People who say there's a difference between Linux's and Windows' interpretation of newline characters, and this compensates for that (with no clear evidence). People who say there's no difference by showing code and output examples, which obviously only applies to that code

R: Getting Unix-like linebreak LF writing files with cat()

亡梦爱人 提交于 2019-12-13 13:42:20
问题 I try to write a character vector to a textfile under Windows 7 / R 3.2.2 x64, and I want unix LF - not Windows CRLF: v <- c("a","b","c") cat(nl,file="textfile.txt",sep="\n") writes > a[CRLF] > b[CRLF] > c[CRLF] cat(paste(nl,sep="\n",collapse="\n"),file="t2.txt") writes > a[CRLF] > b[CRLF] > c I have also tried write.table(eol="\n") - unsuccessfully as it seems to use cat internally. I have looked for other workarounds; I tried to find sth. in R\src\main\scan.c, locating the relevant code in

How to delete line-break in string which is encoded by the function EncodeString with Delphi 7?

我是研究僧i 提交于 2019-12-13 01:26:27
问题 I'am using EncodeString in Delphi 7 to encode strings which load from a source textfile. In the source textfile, every line is one record. Now, I want to use the function EncodeString which is Base64 function to encode every line string and write to a new target textfile. My purpose is one line strings in source textfile should encode to one line encryption strings in target textfile. But every line encode to 3 lines encryption strings. There are several line-breaks made to 3 lines. How can I

RubyMine - How to change end of line character to Windows?

不羁的心 提交于 2019-12-12 14:19:32
问题 I changed a RubyMine settings few days back. It was related to changing the end of line character from '\r\n' to something else, so that it is only Mac compatible. Now, each file I edit is changed completely in git diff. Also, I can't recall which setting option was it. Any guesses? 回答1: File | Line Separator (or the same in status bar, next to file encoding) which will allow to see and change line ending for current file . For newly created files check Settings (Preferences on Mac) | Code

query regarding line feed and fgets()

一世执手 提交于 2019-12-12 01:32:38
问题 Code 1:- int main() { char str[200]; fgets(str,200,stdin); printf("%s",str); return 0; } Output:- ab cd ab cd (line feed) Code 2:- int main() { char str[200]; gets(str); printf("%s",str); return 0; } Output:- ab cd ab cd When I enter ab(space)cd(enter key) , then in case of fgets() I am getting a line feed in the output, whereas in case of gets() , no new line feed is displayed. What is the matter of the line feed in this case. 回答1: gets() and fgets() read for a FILE in to the buffer provided

bash - How to pass a line feed to perl from within a bash script? [duplicate]

流过昼夜 提交于 2019-12-11 18:36:22
问题 This question already has an answer here : How to replace multiple any-character (including newline) in Perl RegEx? (1 answer) Closed 3 years ago . I am trying to replace all digits sequences followed by a line feed and the letter a . Those digits sequences are located in a file called test.txt . The bash script command.sh is used to perform the task (see below). test.txt 00 a1 b2 a command.sh #!/bin/bash MY_VAR="\d+ a" grep -P "^.+$" test.txt | perl -pe "s/$MY_VAR/D/"; When I call the

What is the difference between “\r” and “\n”? [duplicate]

六月ゝ 毕业季﹏ 提交于 2019-12-10 10:46:22
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: What is the difference between \r and \n? I understand that it's different for each operating System, for example, "\r\n" may be expected in Windows, "\n" may be expected in Unix snd "\r" may be expected in Macs. What are the differences between these two (or three, if you want to include "\r\n") escape sequences? Why isn't it consistent across all systems? I'm curious about this. 回答1: Because it just isn't. \r