Note that there are some explanatory texts on larger screens.

plurals
  1. POWhile true not working
    primarykey
    data
    text
    <p>I have the following code: </p> <pre><code>#include &lt;stdio.h&gt; #include &lt;time.h&gt; #include &lt;stdlib.h&gt; #include &lt;unistd.h&gt; int main() { time_t result; char hostname[10] = "ws45new"; char graphite[10] = "127.0.0.1"; char buf[1024]; int n = 0; int num = 0; int graphiteport = 2003; while (1 == 1) { result = time(NULL); n = n + 1; if (n &gt;= 100) n = 0; printf("\n %d", n); // snprintf(buf, sizeof(buf), "echo \"stats.ws45new.test %d %d \" | nc 127.0.0.1 2003", n, result); num = sprintf(buf, "echo \"stats.ws45new1.test %d %d \" | nc 127.0.0.1 2003", n, result); system(buf); printf("\n %s", buf); sleep(2); } return 0; } </code></pre> <p>This is supposed to generate something like a sawtooth signal, which is only for testing. My problem is that when i run the program it doesn't do anything. </p> <p>If i hit Ctrl-C to stop it, the program iterates once through the while loop. It is supposed to send some statistics to a graphite server and I'm using it to understand how graphite is working. From what i've seen it has something to do with the concatenation function <code>sprintf</code> (<code>snprintf</code> also acts the same way). </p> <p>If I comment out that line it works correctly and generates the numbers I want (and also the epoch), but i need the concatenation to be able to send the required dynamic info to graphite. </p> <p>If anyone has any idea why these concatenation functions don't respect the while function please let me know as I'm really curious. Also I'm open to other suggestions but I'd rather not go in to deep, like create sockets and not use nc and system, because i'm not that good with the C language.</p>
    singulars
    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.
 

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