Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

We are to complete this code to read the company names from a database and print them into a text file. I am not sure

We are to complete this code to read the company names from a database and print them into a text file. I am not sure that it will run, because I stuck on the printInfo part. I am not sure I am putting it in correctly. Please check the entire program. Thank you very much. Here is what I have...

#include #include #include // set string lengths #define STRSHORT 15 #define STRMED 30 #define STRLONG 80 using namespace std; // created as a C++ CodeBlocks project

typedef struct company { char name [STRLONG]; char street [STRMED]; char city [STRMED]; char state [STRMED]; char zip [STRSHORT]; char phone [STRSHORT]; char cell [STRSHORT]; int rating; char contact [STRLONG]; }company;

void printInfo(company* info, FILE *fp);

int main() { FILE *fin; FILE *fout; int BlockNumber; char store[STRLONG]; //create an input file name (think up a name) char plumbing[STRLONG]; //create an output file name

company* info= new company;

printf("Enter input file name :"); scanf("%s", store ); fflush(stdin); /* flush keyboard buffer */

// open binary data file if ((fin = fopen("pipes.bin", "rb")) ==NULL) { fprintf(stderr, "Error opening input file."); exit(1); }

printf("Enter output file name :"); scanf("%s", plumbing); fflush(stdin); /* flush keyboard buffer */

// open output text file if ((fout = fopen ("C:/TEMP/plumbing.txt", "w+"))==NULL) { fprintf(stderr, "Error opening output file."); exit(1); } for (BlockNumber=0; BlockNumber<10; BlockNumber++) { /* Move the position indicator to the specified element. */ if ( (fseek(fin, BlockNumber*sizeof(store), SEEK_SET)) !=0) { fprintf(stderr, " Error using fseek()."); exit(1); } /* Read in a single info. */ fread( info, sizeof(company), 1, fin);

fprintf(fout," Block %d ",BlockNumber); //add header text printInfo (info, fout); } return 0; }

int printInfo company(info, FILE *fout ) /? I am stuck here at this printInfo...Error message says that I need an initilizer before company, but on the template it reads

/void printInfo(fill in calling arguments -- company and output file pointers)

{ // print all the info values fprintf (fout,"Name: %s ",info->name ); fprintf (fout,"Street: %s ",info->street ); fprintf (fout,"City: %s ",info->city ); fprintf (fout,"State: %s ",info->state ); fprintf (fout,"Zip: %s ",info->zip ); fprintf (fout,"Phone: %s ",info->phone ); fprintf (fout,"Cell: %s ",info->cell ); fprintf (fout, "Rating: %d ",info->rating ); fprintf (fout,"Contact: %s ",info->contact ); return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Focus On Geodatabases In ArcGIS Pro

Authors: David W. Allen

1st Edition

1589484452, 978-1589484450

More Books

Students also viewed these Databases questions