eranga262154 22 Junior Poster

Or you could do
- find the last \ to mark the start of the filename
- find the last . to mark the end of the filename.

Can you tell me about this more. Any worked example really appreciate.

eranga262154 22 Junior Poster

Hi all,

Using my application I've found a file path anywhere on my machine and store the full path in a CString variable. That is full path, like this,

G:\Work On\CPP\001_002_003.txt

What I want to do is, find the name of the file(without the extension), 001_002_003 according to my example. Then separate as 001 002 and 003, then write them to a file in three columns.

I'm stuck with how to get that three part, 001 002 and 003, from the full file path.

Thanks.

eranga262154 22 Junior Poster

Thanks,

But I cant change my code now for fstram. Have to do lots of modifications.

eranga262154 22 Junior Poster

On my MFC application I read file and do some process on it. Here is the code I used to open and read only.

CFile srf_ReadFile;
char * srf_FilePath = "ReadFile_001.txt";
if(srf_ReadFile.Open(srf_FilePath, CFile::modeRead))
{
// Do the required process here on ReadFile_001.txt
}

So, the file should be always in the same folder which the project/solution contain. If I want to read another file, say ReadFile_002.txt, have to do it manually, go to the code and gives the new file name.

char * srf_FilePath = "ReadFile_002.txt";

It is too boring. So I want to make it more reliable to use. I want to add a browse button(I think that is the correct word, which is used to find the file in Windows) and set it as the file which I want to read.

How can I do it. Can you guys explain.

eranga262154 22 Junior Poster

I've seen it mostly on either north bridge or south bridge chip. As bobbyraw says, name or the logo can be there.

eranga262154 22 Junior Poster

Sorry for misunderstand.

As bobbyraw says, open the case and find the main chip-set. Mostly name of the manufacturer are printed on it.

eranga262154 22 Junior Poster

you need to reinstall windows totally. XP is designed to throw a fit if teh H/W changes to protect against piracy.

Yep, simply all the registries are should be re-written, isn't it?

eranga262154 22 Junior Poster

That mean just print a line, I've test it using my inputs as 4 and 5. Still it give the line 4 == 5. That is 100% correct and I got the point.

Now I know why I'm confusing on this, because at the beginning I used the same inputs.

eranga262154 22 Junior Poster

Hi all,

The topic is my question. I’ll explain it more. Just look at the following C++ code segment,

if(number_1 == number_2);
	{
		std::cout << number_1 << " == " << number_2 << std::endl;
	}

Note that, I have put a semicolon just after the right parentheses. It’s not a syntax error, because at the compile time it not gives an error. So, it should be a logic error. I found that semicolon causes the body of the “if” statement to be empty, from a book. So, there can’t be a output like “5 == 5”, if my input are 5 and 5 on the following code.

#include <iostream>	
//using namespace std;

int main()
{
	int number_1;	
	int number_2;	

	std::cout << "Enter two numbers:\t";
	std::cin >> number_1 >> number_2 ;

	if(number_1 == number_2);
	{
		std::cout << number_1 << " == " << number_2 << std::endl;
	}

	if(number_1 != number_2)
	{
		std::cout << number_1 << " != " << number_2 << std::endl;
	}
	return 0;
}

So where I’m going wrong, my code or my scrap on that book explanation.

eranga262154 22 Junior Poster

It's ok. I got it.

eranga262154 22 Junior Poster

Like this

char * dataBuffer = NULL ;
dataBuffer = new char[dynamic_buffer_size] ;
// work on with buffer
delete [] buffer;
eranga262154 22 Junior Poster

Use system monitoring application. I recommand Everest Home Edition. Download it and run, no need to install either. It gives all the information about your system.

eranga262154 22 Junior Poster

Hi all,

I want to use a dynamic buffer in one of my application. I'll explain it in this way. Depend on one of my calculation I found a number(int value), and I want to define a buffer size to that value. Then after doing all the required process need to clear that buffer size and define it to the next calculated size. Simply it is looping.

So how can I do it.

Thanks.

eranga262154 22 Junior Poster

Actually lots of people hate this MFC. But I feel it is easy to learn.

And as you say, if I can use functionalities like fstream, etc it wont be difficult at all.

eranga262154 22 Junior Poster

he is also running a 64-bit system

I don't think that this is an issue, not depend on version. If you can test your code on that kids' machine.

eranga262154 22 Junior Poster

Thanks pal,

Not a reason to use CFile. Just because you have an MFC program is not a reason to use CFile either. You can mix CFile with fstreams in the same program -- I have done it hundreds of times.

Actually I haven't use it before. If I can use fstream in an MFC application what is the point to use CFile. Any special reason to do it.

eranga262154 22 Junior Poster

Of course, I think my cozy not read the thread carefully or for a long time. Actually on Google lots of articles are available related to this topic.

eranga262154 22 Junior Poster

Have you try to update the BIOS relevant to your motherboard. Check the official web site. There are some details about this.

eranga262154 22 Junior Poster

Normally in such instances, first thing you have to do is check the devices individually with another working machine.

Normally most of the thermal past wont shortened any device. Reason is mainly in contains semi-conductors and avoid the current flow, not completely but up to a certain level. That small current wont damage devices.

eranga262154 22 Junior Poster

You should contact Toshiba ,against forum polices I think to help with bios password , do we really know its yours!!

This is a good point. But everything is depend on the person who done it, right? People should be in trustworthy on such instances. What your comment.

Actually this is not a difficult problem to solve, you may know it better than me.

eranga262154 22 Junior Poster

even the fstream example you posted is not workable.

At the time I post my code it's not workable. But now it works. What I want to do is try the same application with CFile and SQL Server. And also I want to design a GUI for it later.

line 4 does not calculate the size of a file but the number of TCHARs in the file, which might or might not be the same as the size depending on the UNICODE setting.

Actually it works, I check the properties of the file(file which is used to read) and the number of bytes of the file is same as the value given by the above code.

As for CFile, the answer is NO -- and that's one reason why I hate that class. Unless the file contains serialized MFC objects you are better off using normal c++ fstreams, assuming your compiler supports it (some do not).

Most of the time I found that, people don't like MFC. Few reasons I have to use it. First thing is I want to design GUI. Second thing is I'm really new for C++ and MFC, and I'm searching the easiest way to do it.

eranga262154 22 Junior Poster

Try on Google. Lots of online test exam is available. Check on examsonline.com

eranga262154 22 Junior Poster

You should stick to integers and work with them in terms of cents. So 1 = 1 cent rather than 1 dollar in your example. Calculations could also be unnoticably faster as well.

That is a good idea. Floating points normally behave like that, you have explanation on Ezzarals' last post.

Basically used in one format, either in cents or dolors.

eranga262154 22 Junior Poster

Which versions of FireFox you used. Check that you have enable java on FF.

eranga262154 22 Junior Poster

Hi all,

I want to find the end of file in a CFile. What I've do up to now is, find the length of the file in bytes. Then do the required process with the number of bytes. Here is the code,

int length = 0 ;
CString str

length = srf_ReadFile.GetLength()/sizeof(TCHAR) ;
str.Format(_T("File size is %d bytes long."), length) ;
AfxMessageBox(str, MB_OK) ;

My question is there is any simple way to do it. I know on fstream I can do it within one statement, like this.

while(!fileopen.eof())
eranga262154 22 Junior Poster

Yep, I'm sure that the DNS setup is correct. At the time I've tried the SQLOLEDB.1 connection. I think it can be easy to work on OLEDB, do you have any suggestion on that?

I'm really appreciate your comments....

eranga262154 22 Junior Poster

Thanks, but I got the same error on that code as well.

eranga262154 22 Junior Poster

Hi all,

I create a database on SQL 2005 Express edition and link it to a C++/MFC application as follows. It wont gives any compile time errors. But at run time, it gives an error. Here are details.

Link the database in OnInitDialog()

here is the code

BOOL CSRFDBDlg::OnInitDialog()
{
CDatabase srfDB ;
CString srfNAME ;

srfNAME = "ODBC; DSN=.SQLEXPRESS; UID=sa; PWD=sa123; DATABASE=srfdb.mdf" ;
srfDB.Open(srfNAME) ;
if(srfDB.IsOpen())
{
AfxMessageBox("ok") ;
}

srfDB.Close() ;
}

Gives the following runtime error

Data source name not found and no default driver specified

Can you guys tell me where I'm going wrong....

eranga262154 22 Junior Poster

Hi all,

Can you guys explain how can I connect a SQL database to a C++ application(actually my application is a MFC) through ADO.Net

I've use Visual Studio .Net 2003 and SQL Server 2005 Express edition(because I work on WinXP)

If you guys have a simple example, its better to me.

Thanks.

eranga262154 22 Junior Poster

Thanks.

At the same time, I can use SetDlgItemText() member function with passing two arguments, the control ID and string of text.

eranga262154 22 Junior Poster

Yes, "Thinking in C++" is available on the web. You can download it free of charge.

And also http://www.cplusplus.com/ is a best link on the web you can found.

eranga262154 22 Junior Poster

Hi all,

I want to write some text(simply a string of characters) to the edit control on a click event. How can I do that. I know it is able to write something to the control using member function,

GetDlgItemText()

by passing two arguments, control ID and string variable. Is there a similar function which I can use.

Thanks.
Eranga

eranga262154 22 Junior Poster

Yep, but I want to disable it before click the Open button. That mean I want to use inside an event like form load. After all experiment I found that if I declare

GetDlgItem(IDC_CLOSE)->EnableWindow(FALSE) ;

line inside the

OnInitDialog()

Actually it works. What's your comments on it.

Thanks.

eranga262154 22 Junior Poster

Hi all,

In my MFC application I've create two buttons, OPEN and CLOSE, used to open a text file and close it. I do it as follows.

void CSRFToolDlg::OnBnClickedOpen()
{
	char* ReadFileName = "G:\\Work On\\CPP\\SRFTool\\text_file.txt" ; 

	if(openFile.Open(ReadFileName, CFile::modeCreate | CFile::modeReadWrite))
	{
		AfxMessageBox("File creates successfully", MB_OK) ;
	}
	else
	{
		AfxMessageBox("Error in file opening", MB_OK) ;
	}
}


void CSRFToolDlg::OnBnClickedClose()
{
	openFile.Close() ;
}

What I want to do is, until user click the Open button the Close button should be disable. How should I do it. Those stuff really new for me.

Thanks

eranga262154 22 Junior Poster

Here is the main function, I want to read the buffer length equals to (tmp_len - 16) number of bytes. I think this is clear for you.

int main ()
{
	ifstream fileopen ;			
	ofstream filerecord ;
    char buffer[5000] ;
	unsigned int tmp_len = 0 ;	// Length of a stream
	int count_mess = 0 ;		// Count total message
	int ID = 1 ;				// Stream ID

// Open the file in binary format
	fileopen.open ( "G00046_002_01.srf", ios_base::binary ) ;

// Record the stream length
	filerecord.open ( "RecordLength.txt", ios_base::out ) ;

	if((fileopen.is_open()) && (filerecord.is_open()))
	{
	// Set the pointer to the begining of file
		fileopen.seekg (0, ios::beg) ;

	// Headers of the RecordLength.txt file
		filerecord << "Stream ID\tLength\t\tDescription\n\n" ;

	// Headers of the RecordData.txt file
		filedata.open ( "RecordData.txt", ios_base::out ) ;
		if(filedata.is_open())
		{
			filedata << "Destination List\t" << "Member ID\t" << "Data/Message\t" 
					 << "Service ID\t" << "Activity ID\n\n" ;
			filedata.close() ;
		}

		else
		{
			cout << "Error in opening file\n" ;
		}

		while(!fileopen.eof())
		{
			fileopen.read(buffer, 4);	// Dummy read of 4 bytes
			fileopen.read(buffer, 4) ;  // Read next 4 bytes

			tmp_len = *(unsigned int*)buffer ;  // Integer value of previous 4 bytes

			if(tmp_len <= 5000)
			{
				filerecord << ID << "\t\t" << tmp_len << "\t\t" << "-\n" ;

				if(tmp_len > 16)
				{
				// Procesing initial 16 bytes
					fileopen.read(buffer, 16) ;
					dataExtract(16, buffer) ;

				// Move the buffer pointer
					fileopen.seekg((tmp_len - 16), ios_base::cur) ;
				}

				else
				{
					cout << "Stream is in wrong length\n" ;
				}

			}

			else
			{ …
eranga262154 22 Junior Poster

Reason is that, the required byte stream is a part of a stream of bytes. To do earlier processes I used the buffer.

eranga262154 22 Junior Poster

Hi all,

I want to read a stream of bites/bytes as a String.

Here's what I have done up to now. Using a buffer I found that number of bytes, which include a text message from a binary file. Now what I want is to read those bytes stream as a String to get the message.

My issue is, use a buffer of size 5000. Some message use more than that. So I have to iteratively use the buffer cleaning after every read. But confusing, and worried about a simple way.

Thanks.

eranga262154 22 Junior Poster

Thanks for all replays. Actually I'm looking for Visual Studio .Net related materials.

eranga262154 22 Junior Poster

Hi all,

I have a console application, and I want to run it though a GUI. Its a simple GUI. Say there is a button called "Run", when I click the button need to execute the application do the task. Can you guys guide me to do it. I'm really new for C++ GUI developing.

Thanks,

Hi all,

I want to learn how to develop C++ GUI from the basis. So what are the resources(books, tutorials, etc). I use Microsoft Visual Studio .Net 2003.

Thanks.

eranga262154 22 Junior Poster

Dunno then, it works here

#include <iostream>

int main() {
    char c = 'A';
    std::cout << c << std::endl;
    std::cout << (int)c << std::endl;
    return 0;
}

$ g++ -W -Wall -ansi -pedantic  foo.cpp
$ ./a.exe
A
65

Thanks, actually why I'm confusing with this topic is that struct are really new for me.

eranga262154 22 Junior Poster

Yes, that is what I've try.

eranga262154 22 Junior Poster

I've try it and still checking the result with actual one.

By the time I've try to format the output in setbase() of <iomanip> for base 10(because typically it is integer value we use). But it not works. What can be issue there.

eranga262154 22 Junior Poster

You mean simple explicit conversion, like (int) on struct pointer?

eranga262154 22 Junior Poster

I'll explain my issue in this way.

I've use a structure to get some data of a byte stream as follows.

1. struct pac_cont
   2. {
   3.     unsigned int des_list ;
   4.     unsigned int mem_ID ;
   5.     unsigned char dm_con ;
   6.     unsigned char ser_ID ;
   7.     unsigned short act ;
   8.  };

Now I want to write some values finding by using above variables, to a text file, of a function. Try it as follows.

1. void dataExtract(int length, char *buffer)
   2. {
   3.      struct pac_cont* p = (struct pac_cont*)buffer;
   4.        
   5.      printf("dest %d member %d data %d ser %d act %d\n",p->des_list,p->mem_ID,p->dm_con,p->ser_ID,p->act) ;
   6.        
   7.      ofstream filedata ;
   8.      filedata.open( "RecordData.txt", ios::app ) ;
   9.        
  10.     if(filedata.is_open())
  11.     {
  12.              filedata << p->des_list << "\t" << p->mem_ID << "\t" << p->dm_con << "\t"<< p->ser_ID << "\t" << p->act << "\n";
  13.               
  14.              filedata.close() ;
  15.      }
  16.     else
  17.    {
  18.              filedata << "Wrong\n" ;
  19.     }
  20. } 

That printf gives the exact values I need on the command prompt. But the line filedata give some annoying output to the text file. I know that how format the output in printf, but no idea how to use in filedata

Someone can give a clue to me.
Thanks
eranga262154 22 Junior Poster
eranga262154 22 Junior Poster

I think system independent and pure object oriented are the main difference.

eranga262154 22 Junior Poster

If filedata is to be opened and closed in the dataExtract() function, it need not be a global, declare inside the function. As mentioned, use the appropriate file mode to set the writing action to occur at end of existing content (I'd use ios::app ).

Just go through my above post, I think it is not efficient at all.

Why are you passing the data in a char* buffer? Why not just use your struct as the data type of the parameter?

What's wrong there. Actually I've work with a binary file. Extract the streams of bytes, some of them are too short and some of them are too long. Using a buffer it is so easy, what I feel.

eranga262154 22 Junior Poster

That appears to be only part of your program because main() looks incomplete.

Yes, it is a part of the code.

It will work if you use the correct flags. Add std::ate as the second argument to the open function. Read this for more information

Thanks for the link. Actually I've refer the same page to do this. When I used std::ate it wont work. I try to append the data using std::app. It works, but I think it is not efficient, because after writing each line close the file. Isn't it?

>>Only one time write values
No idea because the code you posted does not write anything to the file in main() nor does main() ever call dataExtract().

I'm not clear you. You say that my code is nothing done. If you think that better to put full code here, I'll do it.

eranga262154 22 Junior Poster

Hi all,

I want to use a function to write some values to a text file. That function is called from the main function. Every time when I can that function from main, the perviously written value is overwrite. That's true, it wont work.

So what I have done is open a file globally and use it inside the function. My question is at that time in main function the calling of it not looping. Only one time write values. What can be caused to this issue. Here is the basic view of it.

using namespace std ;

      // Globale file to record exact data
      ofstream filedata ;

      struct pac_cont
      {
          unsigned int des_list ; // Destination list
          unsigned int mem_ID ;   // Member ID
          unsigned char dm_con ;  // Data/Message control
          unsigned char ser_ID ;  // Service ID
          unsigned short act ;    // Activity
      };

      void dataExtract(int length, char *buffer)
      {
          struct pac_cont* p = (struct pac_cont*)buffer;

      // processing the buffer

          filedata.open( "RecordData.txt" ) ;

          if(filedata.is_open())
          {
              filedata << p->des_list << "\t" << p->mem_ID << "\t" << p->dm_con << "\t"
                       << p->ser_ID << "\t" << p->act << "\n";
              filedata.close() ;
          }
          else
          {
              filedata << "Wrong\n" ;
          }
      }

      int main ()
      {
              while(!fileopen.eof())
              {
                  fileopen.read(buffer, 4);   // Dummy read of 4 bytes
                  fileopen.read(buffer, 4) ;      // Read next 4 bytes

                  tmp_len = *(unsigned int*)buffer ;  // int value of 4 bytes

                  if(tmp_len <= 5000)
                  {
                      fileopen.read(buffer, tmp_len) ;
                      filerecord << ID << "\t\t" << tmp_len …
eranga262154 22 Junior Poster

Suns' web site always give the good codes.