Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8465043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:55:48+00:00 2026-06-10T14:55:48+00:00

I have the following code: #include <stdio.h> #include <time.h> #include <stdlib.h> #include <unistd.h> int

  • 0

I have the following code:

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <unistd.h>

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 >= 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;
}

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.

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 sprintf (snprintf also acts the same way).

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.

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T14:55:49+00:00Added an answer on June 10, 2026 at 2:55 pm

    The program most likely gets stuck on the system call.

    You are printing out text without the trailing newline, so it will be kept in the buffer, until a newline is printed, which you do after the system call.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have the following code: #include <stdio.h> int main(void) { float a[4] __attribute__((aligned(0x1000))) =
I have the following code: #include <string.h> int main(void) { char *buffer = NULL,
I have the following code: #include <stdio.h> int main(void) { int x __attribute__ ((aligned
I have the following code: #include <stdlib.h> #include <stdio.h> #include <pthread.h> #define NUM_THREADS 100
I have issues with the following code: #include <stdio.h> #include <stdlib.h> #include <string.h> #include
Say I have the following c program: #include <stdio.h> int main() { printf(Hello world
I have the following C code which works: #include <stdio.h> #include <stdlib.h> #include <string.h>
I have the following code: #include <stdio.h> #include <pthread.h> #define THREAD_CNT 10 #define ITER
This is an ANSI C question. I have the following code. #include <stdio.h> #include
I have the following code: #include<iostream> using namespace std; typedef void (*HandlerFunc)(int, int); HandlerFunc

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.