|
wat's up? you are fighting with CStdioFile for past more than 3 days???
If you need to read data from file, why cant you use fscanf or fstream class? it would be one line cod with that.?
still if you want to use your method, read line by line(i told you that 2 days back?) and use your sscanf function.
|
|
|
|
|
Ya, have been fighting with it for past 3weeks. I can't use fscanf cos i want to set some security. I don't want other user to open the file for reading/writing when my program is using it. Therefore i need to use CFile or CStdioFile. I change my code to
CStdioFile f1;
f1.Open("C:/abc", CFile::modeRead);
int len = f1.GetLength();
char* txt = new char[len+1];
f1.Read(txt, len);
while(_tscanf(txt, "%lf %lf %lf\n", &a, &b, &c) != EOF)
{
.....
....
}
f1.Close();
Using that, it work. But my output result is wrong. The file i am reading consist alot of number and a bit of letter. Thanks
|
|
|
|
|
Sorry if I dont know but is there any such option in CFile that is helping you to block reading/writing access to a file when you are using it and which is not possible with fscanf?
I am not saying what you are doing is impossible or wrong but I used the functions I mentioned before and they were very easy to use. I have never used CFile before. I never felt the need for it..
There must be some special use of CFile..
|
|
|
|
|
Nicholas Amh wrote: My code give me error.
Are you keeping the error a secret?
Nicholas Amh wrote: Can someone help me out with this?
You need to explain: 1) what your program is doing, and 2) what you want your program to do.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi all ..
I am trying to make an exe which will save the data entered by user in a text format.
Its also possible to import the text file to the editbox.. I have four editboxes and these four will be having different data.. but once i store it in text format it will be in one file and during importing the complete data will be in all four edit boxes..
I want to filter out the data for specific editboxes while importing.. Editboxes are Critical, Important, Less Important and Normal.....
Can snybody help me how to filter out the specific data...
iam including my code here.. also my text format...plz hav a look and guide me...
thanku so much
void CNoteDlg::OnOpen()
{
FILE * pFile;
CFile flEdit;
char strFilter[] = { "Text Files (*.txt)|*.txt|*.txt (*.*)|*.*||" };
CFileDialog FileDlg(TRUE, ".txt", "Prioritynotes",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
strFilter,NULL);
if( FileDlg.DoModal() == IDOK )
{
char c;
CString mystring;
pFile = fopen ("D:\\Prioritynotes.txt" , "r");
if (pFile == NULL) perror ("Error opening file");
else
{
while (!feof(pFile))
{
c = fgetc (pFile);
mystring+= c;
if (c=='\n')
{
mystring.TrimRight();
char d[3];
d[0] = 0x0D;
d[1]= 0x0A;
d[2]= 00;
mystring+= d;
m_sedit1 = mystring;
m_sedit2 = mystring;
m_sedit3 = mystring;
m_sedit4 = mystring;
UpdateData(FALSE);
}
}
}
}
}
my format of text file
Date
21/10/2009
Time
4:05:41 PM
**********************
Critical****
--------------------------
Important***
--------------------------
Less Important**
--------------------------
Normal*
--------------------------
|
|
|
|
|
If it's a professional app (which i feel is not the case), then you can use xml with four nodes and data for each node.
If you are making for learning purposes, then just insert a unique tag say <!!!TAG - 001!!!> and then dump all data for tag1. Similarly for tag2,3..
while reading data, search for <!!!TAG - 001!!!> and read data till you reach EOF or another TAG.
Now regarding searching of tags, use something like
while(*fp != '<') fp++;
if(fp == EOF) byebye.
if(read_next_9_characters() != "!!!TAG - ")
then read tag number and check for "!!!>" if it's present.
Read all data for current tag number and store.
Similarly for searching for another tags.
I am sure you can find many articles on searching string in a file in C/C++
An example is here [<a href="http://www.tutorialized.com/view/tutorial/Searching-for-a-string-in-a-File/9990" target="_blank">^</a>]
Other languages like python have built-in search capabilities for regular expressions search which makes this task very easy. other members can put more light on that.
|
|
|
|
|
thanks for the reply....
ya ur assumption is rite. im a student...
iam a beginner in vc++ and hav only very lil background in programming..
this is my first attempt...
may i know how to insert a tag ....
and as per my attempt i need to get the data after the string Critical**** from text file to be printed in first editbox and simlarly the other three...
hope u wud help me out 
|
|
|
|
|
by inserting a tag, I only meant writing some special string in a text file which has very little probability of appearing in the text entered by user. That tag serve as a flag that tells the reader of file that data for a different edit box begin here.
|
|
|
|
|
Have you tried:
CStdioFile file("D:\\Prioritynotes.txt", CFile::modeRead);
CString str;
file.ReadString(str);
m_edit1.SetWindowText(str);
m_edit2.SetWindowText(str);
m_edit3.SetWindowText(str);
m_edit4.SetWindowText(str);
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
hello david.. nice to c u here also
thanks for solving my first doubt ...
dis post was regarding the saving and opening of file.. i hav few strings with me which i need to get displayed in the text file before and in between the text from edit box...
Iam using
CString S1;
CStioFile flEdit;
m_edit1.GetWindowText(S1);
flEdit.Write(S1, S1.GetLength());
how can i make it possible..
before i was using CString every where so i was able to get the text file as per my requirement..
thanks is advance
Date
27/10/2009
Time
11:19:41 AM
**********************
Critical****
--------------------------
Important***
--------------------------
Less Important**
--------------------------
Normal*
--------------------------
|
|
|
|
|
What exactly is the question here? Are you trying to write to a file, or read from it?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
i am able to save the contents of edit box to the text file now.. this is how i did it...
CString S1;
CString A;
CStdioFile flEdit;
CFileDialog FileDlg(FALSE, ".txt","Prioritynotes",
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter);
if( FileDlg.DoModal() == IDOK )
{
if( flEdit.Open(FileDlg.GetPathName(), CFile::modeCreate | CFile::modeWrite) == FALSE )
return;
S1 += "Critical****";
S1 += nextline;
S1 += "--------------------------";
S1 += nextline;
flEdit.Write(S1, S1.GetLength());
A.Empty();
m_edit1.GetWindowText(A);
flEdit.Write(A, A.GetLength());
S1 = '\0';
now i want to retrieve the data under each name to the respective edit boxes once i click open in file menu....
|
|
|
|
|
sonualex wrote: now i want to retrieve the data under each name...
Meaning that you want to read from the file. You do know that CStdioFile has ReadString() (and WriteString() ), don't you?
sonualex wrote: ...to the respective edit boxes...
Using SetWindowText() ?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
yes i know we can use ReadString and WriteString.. but how to combine dat wit CEdit and make it display in edit box i dont know..
plz bear with me ...
|
|
|
|
|
If you are unfamilar with the ReadString() and WriteString() methods, why not consult the documentation?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
thanks again David.. with ur guidance i succeded in completing the project...
my exe is workin fine... iam able to save the contents of editox to text file and import the data from the same text file....
thanking u once again...
my code for OnSave includes
S1 += "Critical****";
S1 += nextline;
S1 += "--------------------------";
S1 += nextline;
flEdit.Write(S1, S1.GetLength());
A.Empty();
m_edit1.GetWindowText(A);
flEdit.Write(A, A.GetLength());
S1 = '\0';
flEdit.Write(S1, S1.GetLength());
flEditClose()
and my code for OnOPen includes
CString mystring;
CString buffer1;
pFile = fopen ("Prioritynotes.txt" , "r");
if (pFile == NULL) perror ("Error opening file");
else
{
while (!feof(pFile))
{
c = fgetc (pFile);
mystring+= c;
if (c=='\n')
{
mystring.TrimRight();
//CODE FOR EXTACTING THE CONTENTS UNDER EACH TITLE
char d[3];
CString test = mystring;
CString crt = "Critical****" ;
CString line = "--------------------------";
CString imp= "Important***";
CString les = "Less Important**";
CString nor = "Normal*";
if(test==crt)
{
mystring ="";
z=1;
}
if(z==1)
{
if(test==imp)
{
mystring =" ";
z=2;
buffer2+=mystring;
m_edit2.SetWindowText(buffer2);
mystring ="";
}
if(mystring !="--------------------------")
{
d[0] = 0x0D;
d[1]= 0x0A;
d[2]= 00;
mystring+= d;
buffer1+=mystring;
m_edit1.SetWindowText(buffer1);
mystring = "" ;
}
}
//SIMILARLY FOR OTHER TITLES....
|
|
|
|
|
It's not very efficient, but if it works for you...
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
ya it works for me perfectly.. thanku 
|
|
|
|
|
Hi Friends
I have function, show below coded in "Test.h"
void Msg()
{
....
}
I copied "Test.h" to include folder of VC++
Can i use Msg function in a project without adding "Test.h" in project solution ?
Just like below
In stdafx.h file
#include <test.h>
thanks in advance
-kk.tvm-
|
|
|
|
|
You have to include Test.h.
You can either include it directly in the file in which you're going to call Msg or you can include it in stdafx.h and then include stdafx.h in the file in which you're going to call Msg.
|
|
|
|
|
|
HI all,
in dialog box i m using GotoDlgCtrl to set focus on button,but this not working in formview.
even i use setfocus from button variable but its also not working.
please tell me what can i use for set focus on button control in formview.
please help me foe this.
thanks in advance.
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
Hello, in my aplication there are two dialogs CCalibracionDlg and DlgMap1 both derived from Cdialog, when I press a button in DlgMap1 i have to send a message to CCalibracionDlg, how can i do this?
I've been trying to do this with PostMessage(hWnd, WM_MYCUSTOMMESSAGE,(WPARAM) wParam,(LPARAM) lParam ); or SendMessage , but in DlgMap1 how can i get the hWnd to CCalibracionDlg?
Thanks in advance.
|
|
|
|
|
How and where in the code are you creating CCalibracionDlg?
You must be having the object of CCalibracionDlg in your appplication. Why cant you share it with DlgMap1 class?
|
|
|
|
|
well i dont think sendMessage is a good option if they are belonging to the same application and thread.
one method will be use FindWindowEx, that give you the handle if you specify the name of the dialog.
Величие не Бога может быть недооценена.
modified on Thursday, October 22, 2009 12:53 AM
|
|
|
|