[Solved] Can’t find issue with “Too many arguments for format” [closed]


all you have to do is correct the %l(there is not such a specifier), you probably should have used %ld.

char *buildStatus()
{
   struct rusage *usage = malloc(sizeof(struct rusage));
   int usageRet = getrusage(RUSAGE_SELF, usage);
   if (usageRet == -1)
   {
      perror("RUSAGE fail");
      exit(EXIT_FAILURE);
   }
   long unsigned cpuTime = (usage->ru_utime).tv_sec + (usage->ru_stime).tv_sec;
   long memUsed = get_memory_usage_linux();
   unsigned int uptime = 0;

   char *message = malloc(1000);
   sprintf(message, "{\"num_clients\": %d,\"num_requests\": %d,\"errors\": %d,\"uptime\": %u,\"cpu_time\": %lu,\"memory_used\": %ld}", (numConnections+1), numRequests, numErrors, uptime, cpuTime, memUsed);
   free(usage);
   return message;
}

hope that helps.

1

solved Can’t find issue with “Too many arguments for format” [closed]