How Much Space Allocate For Sprintf In C

[Solved] How Much Space Allocate For Sprintf In C | Perl - Code Explorer | yomemimo.com
Question : how much space allocate for sprintf in c

Answered by : embarrassed-eagle-p3h6ez40btyd

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main()
{ char *ret; char *a = "Hello"; char *b = "World"; int c = 123; int numbytes; numbytes = sprintf((char *)NULL, "%s %d %s!", a, c, b); printf("numbytes = %d", numbytes); ret = (char *)malloc((numbytes + 1) * sizeof(char)); sprintf(ret, "%s %d %s!", a, c, b); printf("ret = >%s<\n", ret); free(ret); return 0;
}

Source : https://stackoverflow.com/questions/3774417/sprintf-with-automatic-memory-allocation | Last Update : Fri, 29 Jul 22

Answers related to how much space allocate for sprintf in c

Code Explorer Popular Question For Perl