Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Well, re-read the program I sent you via PM. You apparently just ignore it altogether or didn't understand it because I fixed that problem for you.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I think you are a little confused about how to do file i/o. First you have to open the file, next check if the file open succeeded, and finally read the file

in_stream.open("itemlist.txt", ios::in);
if( !in_stream.is_open() )
{
   cout << "Error opening the file\n";
   return 1;
}
// now you are ready to read the file
// read each item in the file
while( in_stream >> itemnum >> price)
{
   // blabla
}
Salem commented: Nice, but I fear the situation is a hopeless case. +20
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

which line(s) are producing those errors? Or are we supposed to guess.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>can i use dosbox for executing those programs

Install and try it yourself to find out.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

vc++ 2008 has an Option to replace tabs with spaces. I haven't figured out how to do the same with vc++ 2010 yet.

The code changes I sent you on allow the program to read the entire file correctly. I did nothing to fix any of the calculations.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You can't make the return value of that function anything other than an integer. Why? Because they are not normal functions -- it acts more like a self-contained process than another function, except that threads have access to all global data in the entire program. So when a thread returns it just goes back to the operating system much like any other program would do.

The code you already put on line 30 should be sufficient. The return value on line 31 is meaningless.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>seriously exactly that
No it isn't. Look at the chart here and you will find a list of all the escape characters that might be found in text files. Your job is to convert them into readable form. For example if you find the tab character which is 0x0a in the file then you would display it as "\t".

To start your program just make a list (array) of all the escape character decimal or hex values, such as 0x0a, 0x09, 0x0b, 0x08, etc. Then you will have to read the file one character at a time and check if its in the array. If it is, then replace it with the printable text as shown in the "Escape Sequence" column of that web site.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>text file contents: hello how are you? = non printing ascii character equivalent

Huh? You mean do the opposite of what we have been telling you? Convert the letter 'h' into some non-printing character such as '\0'? That make absolutely no sense.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

open the file in binary mode then read it 128 bytes at a time

FILE* fp = fopen(arg[2],"rb");
char buf[128];
size_t nBytesRead;
while( (nBytesRead = fread(buf, 1, sizeof(buf), fp)) > 0)
{

}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The value of A is 60, yet you have a loop that assumes its 600. Change that loop like this: for(i=0;i<A;i++)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Im dr. Abeer!!! You are plagiarizing, i will get your ip address and track you down whoever you are! You will fail this course and probably be expelled from the university!

Not from DaniWeb because nobody here is going to do his homework for him.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Why do you have two nested while statements? Are there more lines in the file after EC?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you still have not told us why wordcount is an array of integers.

The function returns 0 because the file stream is already at end-of-file. There's nothing more to read. LoadFile() has already read the whole file, so countWords() has nothing to do.

Suggestion to fix:
(1) delete wordcount array because it is of no value.
(2) delete countword() function because it has nothing to do.
(3) change LoadFile() to return the count of the words read instead of just true or false. It already knows the count -- variable i. So just return its value.
(4) Change the while loop in LoadFile() so that it is similar to the new one you put in countwords().

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Did you open the file before calling that function? Did the open succeed? Is it an empty file?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There could be lots of reasons for that -- other things running on your computer will affect the runtime of your program.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

maybe this will work for you. It doesn't need two counters -- only one is sufficient. If you are trying to read words then why is wordcount an int array instead of std::string array?

int countwords(ifstream& infile, int wordcount[MAX_WORDS])
{
	int count = 0;
	
	while(  count < MAX_WORDS && infile>>wordcount[count])
	{
		count++;
	} 
	return count;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

One way I have done it is to use the standard DOS ^A notation. For all values 1-32 just add 'A' and the caret.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>i have googled it, but no solution.
Not surprised. You are using a 20-year-old compiler (first released in 1991) that knows nothing about windows long file names and paths, can access only about 400K memory even though your PC might have several gigs, could easily corrupt your hard drive if it is larger than 2 gigs, and many other limitations.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

delete the while statement on line 64. It doesn't seem to have a useful purpose.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Ah Ha! I found out why the Build menu was missing -- it was just hidden. Select Tools --> Setting --> Expert Settings and it will appear again.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You have to reset the value of size on each loop iteration

void Registry::enum_key()
{
	int i = 0;
	while( RegEnumKeyEx(hkey , i , name , &size , 0 , 0 , 0 , &filetime) != ERROR_NO_MORE_ITEMS)
	{
		cout << i << ":" << name << endl;
		i++;
		size = sizeof(name);

	}
}
vbx_wx commented: true helper +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Never heard of them either. But after reading this I tink its nothing more than the WHERE clause in SQL statements. SELECT Name,Office,Dep,Rank FROM mytable WHERE dep = 'CS'; That is an SQL example select statement. Put quotes around it, make it a string, then send it to an SQL compliant database, such as MySQL. std::string = "SELECT Name,Office,Dep,Rank FROM mytable WHERE dep = 'CS'"; For more complex examples you need to understand unions and sets.

This all has to do with SQL (Structured Query Language) and databases, not c++, although you can use c++ to access SQL compliant databases.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I've worked with MFC pretty extensively, and I can say for certain that it's at times a pain in the ass. I have not worked with it since VC++ 2005. If you're just getting started with GUI then I'd suggest you learn a more portable GUI package which works with several different platforms. wxWidgets is one, and QT is another. If you want 2d modeling such as for games then try out OpenGL. All of these require a firrm understanding of C and C++.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>enum_key()

Change that for loop to a while loop. RegEnumKeyEx() will return ERROR_NO_MORE_ITEMS when done.

int i = 0;
while( RegEnumKeyEx( /* blabla */)  != ERROR_NO_MORE_ITEMS )
{

}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

--> arrow like this what they are working?? i neva use in my c code.

You need to read and study pointers. This link is a good tutorial

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Writing binary file would be more efficient, but unreadable with any standard text editor such as Notepad. Note that file_out has to be opened in binary mode.

file_out.write( (char *) atoms, sizeof( atoms));
file_out.write( (char *)&origin_x, sizeof(origin_x));
file_out.write( (char *)&origin_y, sizeof(origin_y));
file_out.write( (char *)&origin_z, sizeof(origin_z));

Then to read it back, just replace write() with read()

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>i want to write this program without lib and string files

Not possible. You need standard C libraries in order for your compiler to produce the executable program. If you don't want any libraries then you have to first delete (remove) all those header files in lines 1 to 4, then write your own version of malloc(), free(), printf(), etc. Or maybe that wasn't really what you want. If not, then you will have to provide more information.

Remember, we will not write your program for you. Ask specific questions and we will try to answer them.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I want to store each line separately

@Aia: I'm not sure exactly what he meant by that, do you? My guess was that he wanted to store the lines in memory. One way would be to declare a whole bunch of pointers, but a more reasonable way is to store them in an array of pointers. I also assumed (maybe wrongly) that the OP has a brain and he/she can use it to figure out how to put the code I posted in a loop. But maybe that was just asking too much.

Like anything else there are other ways to do it, such as linked lists. But I doubt the OP knows anything about them -- yet.

Aia commented: "That's the general idea for you". Broken code and half ways are you cup of tea. -2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Yes, like that. But its going to be a little difficult getting the variables back because you put so much verbiage into the file. Only write the data and it will be easy to read back

void Account::account_details(ostream& out) {
	out << number << " " << balance << " " << rate << "\n";
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Download and install MySql++. Its a free c++ class for MySQL databases. Of course you will have to have MySQL installed on your computer.

If you have VC++ 2008/2010 Pro or better edition I believe it has all the plugins you need to create and maintain databases. But if you have the Express edition then you need either MySQL++ or use ODBC API calls.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Unfortunately I did try adding the class declaration before and it resulted in a further error where Visual Express told me that there was an error in adding the class declaration again...

I'll try again.

I posted it EXACTLY as you should have coded it. All you had to do is copy/paste into your program. You even quoted it just an hour ago (see your post #4 in this thread).

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Create an array of pointers, then read each line and add to the array

char *data[200]; // 200 lines of data
char line[255]; // one line from the data file
fgets(line, sizeof(line), fin);
data[0] = malloc( strlen(line) +1);
strcpy(data[0], line);

Now put the above in a loop so that it reads the entire file. Increase the array size if needed so that it will hold all the lines in the file.

Aia commented: Nonsense -2
adrawat commented: Amazing answer !!! +1
Nick Evan commented: If the OP is happy, I call it a good enough post. +12
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

read it back in the opposite direction that it was written.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

move lines 9-11 up to between lines 1 and 2. As coded, line 4 can not use cout because it doesn't know what cout is.

Other than that, what is the problem with your program?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 35: >> Account_array.account_OutPutdetails(file);

Nope. Change SIZE to 0, such as Account_array[0].account_OutPutdetails(file);

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Look at line 13. Don't you see the error in that line?? Hint: look at the semicolon at the end of the line.

And you failed to add the class declaration Triangle::Triangle(i// blabla)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Apparently there are other similar errors. Find and fix them. Hunt and destroy!

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
void Engine::LoadHistory()
{
    FILE *lfile;
    bool bContinue = true;
    int read,count = 0; // TEST
    char buf[50];

    lfile = fopen(TRAINING_LIST,"r");
    read = fscanf(lfile,"%s\n",&buf);

The problem is here. Check if the file was opened and quit if not.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I've tried doing that, but to no avail.
Then you did it wrong. Post what you tried.

Put them exactly as I posted them. Some people like to do it like below. Do it which ever way you want, or however your instructor told you to.

Triangle::Triangle(int side1,int side2,int side3) {

}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Is this better??

No. line 31 needs to pass the ofstream object as a parameter Account_array[x].account_details(myfile);

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Well, I'm not about to fix the bug for you. You can do it, so you fix it. If the program compiles ok with VC++ express then you should be able to run it ok too. The error message you posted would happen regardless of the compiler. You just have to figure out what caused it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I'm confused about what you mean by send to a data file? Or data queue? Are you talking about sockets -- sending packets via sockets to another computer? Or are you talking about copying a file 128 bytes at a time ?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>When I do a break point the subjectcode is 84 T. Is the 84 the equivelant to T?

Yes -- look at any ascii chart and see for youself. subjectcode is declared as char, therefore the >> operator will treat is as such. Declare it as an int then test again to see if that fixes the problem. If it doesn't then post a few lines of the data file so we can see what the program is trying to read.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Did you also add the parameter it in the class declaration for that function?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Find out where you are calling fscanf() then check that the FILE stream has been opened successfully (check if it's not NULL). You probably are not checking if fopen() succeeded.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It doesn't write to the file because account_details() only writes to the screen. To fix that I would add a parmeter which would be either cout or an ofstream object

void Account::account_details(ostream& out)
{
   out << // blabla
}

example:

#include "stdafx.h"
#include <iostream>
#include <fstream>
using namespace std;

#include<string>

using namespace std;

void foo(ostream& out)
{
	out << "Hello World\n";
}

int main()
{
	foo(cout);
	ofstream out("myfile.txt");
	foo(out);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Does this mean I have an error within the program,
Yes, your program is buggy. Coding and getting a clean compile is only about 25% the job of a programmer. The other 75% if fixing bugs.

>>or could there be an error in the compiling process?

Unlikely. Don't blame the compiler for your buggy program.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Use the <map> class to create a list of file extensions and file sizes. As the files are read then update the map. When done just display the map contents. boost will not do that for you, you have to code it yourself.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Sorry I didn't respond earlier -- I was at work.

You didn't say you needed to count the number of lines in the file. To do that use getline(), then split up the line into integers using stringstream

#include <sstring>
...
std::string line;
while( getline(dataFile, line) )
{
    m++;
    stringstream str(line);
    while( str >> Val )
    {
       // blabla
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Very few, if any, members here know what those SDL functions are. Is that a library of some kind? If it is, post the link to it.