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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:30:40+00:00 2026-06-07T17:30:40+00:00

I’m currently taking a course on structured programming methods. The course is not language

  • 0

I’m currently taking a course on “structured programming methods”. The course is not language based, but we generally use either C or C++. Sometimes I’m required to write in one of these languages, sometimes I have to initially write in C and covert the code to C++, and sometimes I am allowed to write in what I prefer. Quite possibly odd, I prefer to utilize C’s (f/p)rintf. So, here’s my issue:

This is my header file for the struct:

 #include <string>
 using namespace std;

 typedef string FNAME;
 typedef string LNAME;
 typedef string FULLNAME;
 typedef struct EmpRecord
 {
    FNAME firstname;
    LNAME lastname;
    FULLNAME fullname;
    float  hours, rate, deferred, gross, netpay,
           fedtax,  statetax,  ssitax;
  } EmpRecord;

Here’s the “main”.cpp:

        #define STRADD ", "
        #include <stdio.h>
        #include <iostream>
        #include <fstream>
        #include <iomanip>
        #include <string>
        #include "Struct.h"
        #include "Rates.h"
        #include "calcTaxesPlus.cpp"
        using namespace std;

        /*......*/
        void printEmpData(FILE *fp, struct EmpRecord *, float reghrs, float othrs);//3.8
        /*......*/
        int main()
        {
            float totRegHrs, totOtHrs, totRates, totGross, totDeferd,
                  totFed, totState, totSSI, totNet;
            float reghrs, othrs;
            float avgRate, avgRegHrs, avgGross, avgFed, avgSSI, avgNet,
                  avgOtHrs, avgState, avgDeferd;
            int   numEmp;

            EmpRecord emp;
            EmpRecord *Eptr;
            Eptr = &emp;

            FILE * fp;
            fp = fopen("3AReport.txt", "w");
            if (fopen == NULL)
            {
                printf("Couldn't open output file...!");
                fflush(stdin);
                getchar();
                exit(-1000);
            }
            /*....*/
            printEmpData(fp, Eptr, reghrs, othrs);//3.8
            return 0;
        }
        /*....*/
        void printEmpData(FILE *fp, struct EmpRecord *e, float reghrs, float othrs) 
        {
            fprintf(fp, "\n%-17.16s   %5.2f       %5.2f     %7.2f     %6.2f     %6.2f %7.2f", e->fullname, e->rate, reghrs, e->gross, e->fedtax, e->ssitax, e->netpay);
            fprintf(fp, "\n                                %5.2f                 %6.2f     %6.2f       \n", othrs, e->statetax, e->deferred);
        return;
    }

I have tried a ton of combinations suggested by other questions/answers, but none seem to be dealing with a cross-language situation.

I’m basically looking for a solution that permits me to continue to use fprintf while leaving the bulk of the code C++.

I’m not looking for someone to code the solution for me, rather to explain what the issues are with this and how to logically go about circumventing them.

Also, typedef is a requirement.
Thanks-

  • 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-07T17:30:42+00:00Added an answer on June 7, 2026 at 5:30 pm

    std::string has a c_str() const method that you can use to “prep” a std::string for formatting with %s:

    fprintf(fp, "%s", e->fullname.c_str());
    

    When a printf-style function sees %s in the format string, it is looking for a NUL-terminated C string (type: const char *). The std::string::c_str() const method returns just that for the std::string object.

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

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I need to clean up various Word 'smart' characters in user input, including but
I am currently running into a problem where an element is coming back from

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.