See this code:
int main() {
char a[50];
FILE *fp;
fp = fopen("test1.txt", "w");
sprintf(a,"jigar %d \n", 3);
fprintf(fp,"jigar %d \n", 3);
sprintf(a,"patel %d \n", 2);
fprintf(fp,"patel %d \n", 2);
printf("%s", a);
}
Here, using fprintf, I can write in file
jigar 3
patel 2
where same functionality I want where what ever I print that goes in one char buffer.
but using sprintf gives me on buffer
patel 2
I have so many such print which I want to add in one char buffer and then I need to return it to application so how to get it in simplest and fastest way this?
sprintf()returns the number of characters printed.Just use that number for the next write …
Make sure you don’t cause any buffer overflows though.