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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best Method For Writing Fixed Length Text File With Cursor

Status
Not open for further replies.

jtrapat1

Programmer
Jan 14, 2001
137
0
0
US
I'm using C Programming and am trying to write out a fixed length text file.
The text file will be the result from a SELECT query against DB2 database tables.
-----------------------------------------
EXEC SQL
DECLARE C1 CURSOR FOR
SELECT bp73.adds_id, bp73.priority, bp70.last_name, bp70.first_name
FROM nysa.bp73t_req_by bp73
JOIN nysa.bp70t_member bp70
ON bp73.mbr_id = bp70.mbr_id
WHERE bp70.budget_yr = :bp70.budget_yr;
----------------------------------------
The data needs to start and end in certain positions so it can be read by a macro in an access database.
What is the best method to use for my case?
So far I have used fprintf but I don't think I can control which positions I can place the data.
Here's my code:
----------------------------------------------------
fprintf(output,"%li,%s,%s,%s\n,",
bp73.adds_id, bp73.priority, bp70.last_name,
bp70.first_name);
-----------------------------------------------------
Could I use fwrite or is there another alternative?
I tried fwrite but I think I got the syntax incorrect.
I'm looping thru the cursor and am trying to print out each record to the text file.
Here's what I tried:
------------------------------------------------------
fwrite(&C1,sizeof(C1),1,output);
(where C1 is my cursor)
----------------------------------------------------

Thanks in Advance.
John
 
format it:
#define FMT 10
fprintf(output,"%*li,%-*.*s,%-*.*s,%-*.*s\n,"
,FMT,aaaa
,FMT,FMT,bbbb
,FMT,FMT,cccc
,FMT,FMT,dddd
); -----------
when they don't ask you anymore, where they are come from, and they don't tell you anymore, where they go ... you'r getting older !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top