Note that there are some explanatory texts on larger screens.

plurals
  1. POfwrite add new line after each input
    primarykey
    data
    text
    <p>I wanted to add a new line to separate each entry in the file.</p> <p>I tried:</p> <pre><code>show_dump(buff + "\n", len, dump_fd); </code></pre> <p>But got an error with that.</p> <p>I got this function from somewhere else, It formats the buffer sent from the client into hex and ASCII data.</p> <pre><code>/* Usage: show_dump(buffer, buffer_length, stdout); show_dump(buffer, buffer_length, fd); */ #include &lt;string.h&gt; void show_dump(unsigned char *data, unsigned int len, FILE *stream) { const static char hex[] = "0123456789abcdef"; static unsigned char buff[67]; /* HEX CHAR\n */ unsigned char chr, *bytes, *p, *limit, *glimit = data + len; memset(buff + 2, ' ', 48); while(data &lt; glimit) { limit = data + 16; if(limit &gt; glimit) { limit = glimit; memset(buff, ' ', 48); } p = buff; bytes = p + 50; while(data &lt; limit) { chr = *data; *p++ = hex[chr &gt;&gt; 4]; *p++ = hex[chr &amp; 15]; p++; *bytes++ = ((chr &lt; ' ') || (chr &gt;= 0x7f)) ? '.' : chr; data++; } *bytes++ = '\n'; fwrite(buff, bytes - buff, 1, stream); } } </code></pre> <p>This is how I'm creating the file:</p> <pre><code>if(dump) { add = dumpfile; for(i = 1; ; i++) { sprintf(add, "%d.log", i); dump_fd = fopen(dumpfile, "rb"); if(!dump_fd) break; fclose(dump_fd); } dump_fd = fopen(dumpfile, "wb"); if(!dump_fd) std_err(); } </code></pre> <p>And this is how I'm writing into the file:</p> <pre><code>if(dump_fd) show_dump(buff, len, dump_fd); </code></pre> <hr> <p>Question: Whats wrong with the code? Why is the files all written together and not line by line?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload