Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Beginner, Help with conversion file.

Status
Not open for further replies.

johnncc

MIS
Oct 2, 2002
15
US
Hi.
I have this program that is supposed to take a tab delim file and create a fixed length. When I comppile this code it gives an error: E:\dialer_conversion.cpp(35) : error C2664: 'fgets' : cannot convert parameter 3 from 'char *' to 'struct _iobuf *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast.

I can't figure this out. Any help will be appreciated. If there is some material I can read on this or if someone knows a fix anything will help. Code below.

Code:
// this program will open a tab file and save as fixed length
#include <stdio.h>




int main()

{


	// set file pointers
	FILE *dialPtr;
	FILE *smartPtr;

     // input tab file name
	char *myFile;
	
	//input file to convert
	printf("Enter the file to convert: (dialer.txt).\n> ");
	scanf("%s", myFile);

	//check if files are open
	if (((dialPtr = fopen (myFile, "r")) = NULL) && ((smartPtr = fopen ("smartout.txt", "w")) = NULL))
	
	//if not open
	{
		printf("Unable to open file.\n");
	}
	else{

		//process files
		char line[4096];

		

		while (fgets(line, sizeof(line), myFile))
		{
			char *rec;
			char *clNum;
			char *clName;
			int acct;
			char *dbtr;
			char *addy;
			int phone;
			char *pt;
			int assign;
			char *stat;
			char *desk;
			int tot;
			int lstPay;
			int lstWork;
			char *state=line;//buffer

			//extract info from buffer
			rec = "REC00004A1";
			clNum = strsep(&state, "\t");
			clName = strsep(&state, "\t");
			acct = atoi(strsep(&state, "\t"));
			dbtr = strsep(&state, "\t");
			addy = strsep(&state, "\t");
			phone = atoi(strsep(&state, "\t"));
			pt = strsep(&state, "\t");
			assign = atoi(strsep(&state, "\t"));
			stat = strsep(&state, "\t");
			desk = strsep(&state, "\t");
			tot = atoi(strsep(&state, "\t"));
			lstPay = atoi(strsep(&state, "\t"));
			lstWork = atoi(strsep(&state, "\t\r\n"));

			//send to file
			fprintf(smartPtr, "%-10s%-10s%-30s%-10d%-10d%-30s%-25s%-10d%-30s%-6d%3s%-5s%5d%-8d%14d%-6d\n", rec, clNum, clName, phone, account, dbtr, addy, phone, pt, assign, stat, desk, tot, tot, lstPay, lstWork);
		}
	
		//close files
		fclose(smartPtr);
		fclose(dialPtr);
	}

	//success
	return 0;
}
[\code]
 
Code:
while (fgets(line, sizeof(line), [red]myFile[/red]))
Since the 3rd parameter is supposed to be a [tt]FILE*[/tt], I would assume that you instead meant this.
Code:
while (fgets(line, sizeof(line), [blue]dialPtr[/blue]))
Of course, first you should allocate some memory into which to receive the filename rather than just leaving it dangle:
Code:
char *myFile;
Perhaps change it to this:
Code:
char myFile[128];
Also, [tt]#include <stdlib.h>[/tt] since you are using stuff from it, and [tt]#include[/tt] whatever header declares [tt]strsep[/tt]. And watch out here:
Code:
if ( ((dialPtr = fopen (myFile, "r")) [red]=[/red] NULL) && ((smartPtr = fopen ("smartout.txt", "w")) [red]=[/red] NULL) )
A comparison is [tt]==[/tt] and an assignment is [tt]=[/tt].
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top