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 7850625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:55:14+00:00 2026-06-02T18:55:14+00:00

See this code: int main() { char a[50]; FILE *fp; fp = fopen(test1.txt, w);

  • 0

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?

  • 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-02T18:55:16+00:00Added an answer on June 2, 2026 at 6:55 pm

    sprintf() returns the number of characters printed.

    Just use that number for the next write …

    int i;
    char a[50];
    char *ap = a;
    
    for (i = 5; i < 15; i++) {
        ap += sprintf(ap, "%d ", i);
    }
    
    printf("%s\n", a); /* "5 6 7 8 9 10 11 12 13 14 " */
    

    Make sure you don’t cause any buffer overflows though.

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

Sidebar

Related Questions

This is my code: #define LEN 40 #define STUDLIST ./students.txt int main() { FILE
Please see this piece of code: #include<stdio.h> #include<string.h> #include<stdlib.h> int main() { int i
see my code is #include <stdio.h> #include<stdlib.h> #include<sys/stat.h> int main(int argc, char**argv) { unsigned
In facebook tutorials I see this sample code: @Override public void onActivityResult(int requestCode, int
The below code is writing unreadable characters to the text file: int main ()
See this code: var jsonString = '{id:714341252076979033,type:FUZZY}'; var jsonParsed = JSON.parse(jsonString); console.log(jsonString, jsonParsed); When
So here's what I see this code doing: An array is made A loop
i'm playing with MEF and in the example i see this code ( i
I have this code below. As you can see I am passing two variables
it's common to see something like this in code, hopefully only during development: //XXX:

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.