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

  • Home
  • SEARCH
  • 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 8096053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:19:58+00:00 2026-06-05T21:19:58+00:00

I am calling a function funcB from funcA . funcB uses several printf statements

  • 0

I am calling a function funcB from funcA.
funcB uses several printf statements to output data.
Is there a way for me to capture that data via funcA?
I can not modify funcB.

funcB(){
     printf( "%s", "My Name is" );
     printf( "%s", "I like ice cream" );
}

funcA(){
    funcB();
}
  • 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-05T21:20:01+00:00Added an answer on June 5, 2026 at 9:20 pm

    (This answer is a corrected version based on this answer.)

    This answer is POSIX centric. Use open to create a file descriptor for the file you want to redirect to. Then, use dup2 to STDOUT_FILENO to change stdout to write to the file instead. But, you’ll want to dup the STDOUT_FILENO before you do that, so you can restore stdout with another dup2.

    fflush(stdout);
    int stdout_fd = dup(STDOUT_FILENO);
    int redir_fd = open(redirected_filename, O_WRONLY);
    dup2(redir_fd, STDOUT_FILENO);
    close(redir_fd);
    funcB();
    fflush(stdout);
    dup2(stdout_fd, STDOUT_FILENO);
    close(stdout_fd);
    

    If funcB is using std::cout, use std::cout.flush() instead of fflush(stdout).

    If you want to manipulate C++ streams more directly, you can use Johnathan Wakely’s answer.

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

Sidebar

Related Questions

I have an unmanaged dll that contains a function to read a data from
I'm trying to return a value from (transport) to the calling function, but can't
Suppose you are calling a function, where there's clearly a need to break down
I am calling a function in my controller from a button click .... I
I am calling a function and passing 3 parameters to that. I am taking
I would be calling procedure or function from java using JDBC . In terms
Is it possible that when calling multiple times this function: void Func(String spr, PictureBox
I have strange problem, with calling Lua function from C++. I have in Lua:
Does anyone know how to watch a variable in calling function. For example: C#:
I'm calling a function and adding a listener for when the function returns some

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.