-
fprintf to text file
Ok, I've got a text file say like below:
Imperial Imperial
1 0001010000000000000000000000 5000
0 0
ROOF BASICS
22 96.000000 0.463648 0.000000 12.000000 12.000000 1 1 1
4.163119 4.163119 3.500000 3.500000 3.500000 3.500000
0.250000 0.250000 24.000000
0.000000 0.000000
Two things are causing me a problem. I'm not sure if the problem is being caused by my \n or what but if anyone can offer any suggestions, that would be great.
1) If I change the 22 to 3 in line five, I close the file and wind up with 32. How can I get rid of the 2 and truncate the remainding text to allow only one space between data.
2) When I modify line six, I end up with line seven missing 0 in 0.2500000 (looking like .2500000)
Thanks,
Ray Schmidt
Code:
void CPeekaViewDlg::OnSave()
{
UpdateData(TRUE);
FILE *stream;
char s[255];
char file[100];
char getl[100],getl2[100];
int i=74,skipper=0,z=0,hb=0;
//select & open file
if(m_quote == 0)
{
// Quote Directory
sprintf(file,"c:/mydocu~1/programming/peekaview/%s.tre",m_truss);
//sprintf(file,"j:/mitek/quote/%s/%s.tre",m_job,m_truss);
if( (stream = fopen(file,"r+")) == NULL )
{
MessageBox(" Trusses Not Found!\nFill In The Information Below", "Error", MB_ICONEXCLAMATION);
return;
}
}
if(m_quote == 1)
{
// Production Directory
sprintf(file,"c:/mydocu~1/programming/peekaview/debug/%s.tre",m_truss);
//sprintf(file,"j:/mitek/prod/%s/%s.tre",m_job,m_truss);
if( (stream = fopen(file,"r+")) == NULL )
{
MessageBox(" Trusses Not Found!\nFill In The Information Below", "Error", MB_ICONEXCLAMATION);
return;
}
}
//quanity
fseek(stream, i, SEEK_SET);
fscanf(stream,"%s",s);
skipper = strlen(s);
z = i + skipper + 1;
fseek(stream, z, SEEK_SET);
fgets(getl,55,stream);
fseek(stream, z+56, SEEK_SET);
fgets(getl2,54,stream);
m_qty == &m_changeqty;
i = 75;
fseek(stream, i, SEEK_SET);
if(strlen(m_changeqty)==1)
{
fprintf(stream, "%s", m_qty);
}
if(strlen(m_changeqty)>1)
{
fprintf(stream, "%s%s\n", m_qty, getl);
fseek(stream, z+55, SEEK_SET);
fprintf(stream, "\n%s\n", getl2);
}
if(strlen(m_changeqty)>2)
{
fprintf(stream, "%s%s\n", m_qty, getl);
}
fclose(stream);
m_workc = getl2;
UpdateData(FALSE);
}
-
You are trying to process the file as a binary file, but the format of the file is sequential text. There is another thread from recently that goes over processing a file in binary...I wont rehash it here. I think the thread is called "Deleting/Searching Directly File I/O", it is about a page back if you look for it.
-
here is a link to the mentioned thread:
http://cboard.cprogramming.com/showt...threadid=34807
There is a wealth of file i/o information here on the boards, a quick search may prove to be all you need.