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

The while loop that I posted previously will read all the lines in the file no matter how big the file is. It will read a file with just one student or a file that contains a million students.

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

are you trying to do big/little endean swapping?

unsigned char buf2[4];
buf2[0] = buf1[2];
buf2[1] = buf1[3];
buf2[2] = buf1[0];
buf2[3] = buf1[1];

unsigned int x = *(unsigned int*)buf2;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You should be asking these people. I don't think Dev-C++ knows how to compile the resource files, but there are several free resource compilers available via google.

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

www.codeproject.com has several printing programs that will show you how to do that. Some are for MFC and some not. That site has hundreds of programs and tutorials covering almost everything Windows programming has to offer.

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

>>if (textBox1->Text="Filip")
My guess is the above line is wrong. textBox1 can not be used in an if condition like that. Change the = operator to == and see if that fixes it.

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

There is a whole thread just about books in the Read Me threads at the top of the c++ forum

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

>>I cant seem to find any good ebooks. Thank you.
You probably won't find any free ones either. Authors don't write books for the hell of it. They do it to make money. You will get better books at amazon.com or your local book store.

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

>>is there a way to do this same thing, only with a short.
you mean something like this: where buffer contains the binary bytes of a short integer?

short int X = 123;
char buffer[sizeof(short)];
memcpy(buffer, &x, sizeof(short));
...
...
// now put it back
short int n;
n = *(short *)buffer;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

delete lines 70 and 71 because the program already knows the filename from lines 13 and 14. No point in asking for the filename again.

line 75: fscanf() is mal-formed. Here is correction

while(fscanf(fp,"%s%s%s%d%f",
        name,
        course_enrolled,
        date_of_birth,
        &id_number,
        &average) > 0)
    {
        fprintf(stdout,"NAME= %s\tCOURSE ENTITLLED= %s\t ID NUMBER= %d\t DATE OF BIRTH= %s\tAVERAGE= %f\n",name,course_enrolled,id_number,date_of_birth,average);
    }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>>>>line 15: remove the quotes around filename.
i removed quotes at line 15 and


>>>>line 74: you close the file at the end of the first loop iteration. Move that line down after the }
closed file after first for loop

And the results were ???

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

I hesitated to do this because I can't install the DLL on all of the machines that will need to run this code. I understand that what I did is useless, but I'm not convinced it'll be useful to go around manually dragging a DLL into everybody's c:\windows directory either

That suggestion was for testing purposes on your development computer only. Final release version you should install the DLL in your program's application directory then add the path to that directory to the computer's PATH environment variable.

... especially seeing as doing just that did nothing -- with the DLL in c:\windows I'm still getting the same error.

At the command prompt enter the word PATH, press <Enter> key, and look to see if c:\windows is one of the paths that your computer displays. If not, put the dll in another directory that is in the PATH.

When I write a program that uses a DLL I link the program with the DLL's *.lib file which was created by the compiler when you compiled the DLL.

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

line 12: increase the array size of filename to 255 characters so that it can hold the maximum number of characters the operating system allows for a filename.

lines 13 and 14: uncomment those two lines.

line 15: remove the quotes around filename.

line 74: you close the file at the end of the first loop iteration. Move that line down after the }

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

my PATH environment contains the folder that the DLL is being placed into... er... by that I mean I added the DLL's path to the additional dependencies directory...?

I see you failed to do the test I asked you to do, consequently what you did was useless. The additional dependencies path in your compiler's IDE means nothing at runtime.

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

In c++ they are the same.

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

post code, such here is how it might be done

char buffer[512] = "Hello World";
// allocate memory for the new string
char* ptr = new char[strlen(buffer)+1];
// now copy
strcpy(ptr, buffer);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I like VS2008 (VC++ Express) the best. ... and it's backwards-compatible with VC6.

No it isn't backward compatible because VC++ 6.0 did not support the c++ standards very well. Code written with VC++ 6.0 will encounter some porting problems when compiled with VC++ 2005 or newer compilers.

Don't bother trying to get a free version of VC++ 6.0 because it really sucks. VC++ 2008 is a much better compiler, but doesn't include some of the whistles & bells that was in VC++ 6.0, such as MFC.

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

It means what it says. Post code because I can't see your monitor.

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

im not to sure if i understand what your saying. I need to create an array of unsigned int? Then store the offset of each line into the array? Then use those values to seek to the desired line??

I guess you have never worked with arrays before?? Note: ivailosp had a better idea.

#include<iostream>
#include<fstream>
#include <string>
#include <vector>
using namespace std;

int main()
{
    int lineCount=0;
    fstream file;
    char filename[10];
    string line;
    vector<size_t> offsets; 
    cout << "Enter file name" << endl;
    cin >> filename;

    file.open(filename);
    if(file.good())
    {	
        cout << "file opened successfully" << endl;
        string t;
        while(getline(file, t, '\n'))
        {
            ++lineCount;
            size_t cnt = file.tellg();
            offsets.push_back(cnt);
        }
    }
    else
    {
        cout << "Error file does not exist" << endl;
    }
    file.clear(); // clear eof error flag 
    if(file.good())
    {	
        int x = lineCount - 10;

       file.seekp (offsets[x], ios::beg);
		
        while(getline (file, line))
        {
            cout << line << endl;
        }
    }
    file.close();
		
    return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>what's wrong with these 3 codes
I don't know -- what do YOU think is wrong with them?

As for the second program, the defulat data type of a const is an integer, which has no decimals. So this is how to declare the const const float taxRate = 0.175; Then the calculation becomes very simple return priceExclVAT * (taxRate + 100.0F);

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

you need a vector<unsigned int> that contain the offsets for each line. Create that array during the loop on line 24. For each line call tellg() to get the offset. Then you can use that info on line 42.

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

Weight Watchers Zero Points Garden Vegetable Soup ♥ . Good thing about that receipe is that you can put whatever you want in it and the soup will be just great. I used green beans instead of peas, increased stalk to 8 cups (because that's how much comes in the packages I bought), added celery, pepper, and for added spice some sliced jalapeno peppers/juice.

This makes a lot of soup, probably enough for at least 6 people, or enough to last one person 3 means/day for a week :)

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

I listen to talk radio when I'm in the car, otherwise I don't listen to it. If the station is talking sports then I turn it off and listen to CDs while driving.

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

copy the dll into the windows installation directory such as c:\windows and see if that fixes the problem. If it does fix it then you just need to put the dll into one of the paths that is in your PATH environment variable.

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

That appears to be more trouble than its worth

std::string name;
float gpa;
infile.open("C:\\progpa.txt");  
while( infile >> name >> gpa)
{
    // now do something with them
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

For specific compiler instructions its best to ask the people who wrote the compiler. Click here

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

>>gets(data);
Click here

>>it is not letting me scanf in first code but when i manually take
Now how do you expect a program to have keyboard access when its running in the background? Keyboard hits only go to the topmost forground program.

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

Don't get these questions firmly fixed in your head, they are absolutely unimportant on a fresher in C stage...

You're right about that -- there was a time 20 years ago when those two questions were very important for programmers because programs were limited to 640K of memory. But times changed and made the two questions nearly obsolete. They are however still relivent on a few obscure operating systems such as embedded systems where memory is very limited. But on a PC running either *nix, MS-Windows, or MAC you don't need to be concerned much about program size or stack size unless you want to write a really gigantic program.

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

The reason is that you did not include the correct library. Look up that function in MSDN and it will tell you what library you need. Go to www.microsoft.com and enter OpenPrinter in its search box, it will give you a list of links. Select the first link in the list, when the page comes up, scroll down to the bottom and you will see the name of the library you need.

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

that loop is constructed incorrectly

while( getline(infile, line) )
{
    cout << line << "\n";
}

>>give. I imagine we have to put a counter/loop inside the file so it can differentiate between the name's and
All you have to do is put the name on the same line as GPA. Look at the file with Notepad.exe or some other text editor so that you can easily see the file's contents.

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

I would use a c++ library such as DirectX or OpenGL that does all the difficult GUI stuff for games. There are lots of tutorials.

c++ is not good at browser stuff, like Java. C# is better than C++, but for browsers java IMO is better than either of them. win32 api has functions similar to JPanel in a JFrame, but you may not need them with DirectX or OpenGL.

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

Oops! sorry but it should be << not >> file << "*&^@";

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

Calling one constructor from another cause the destructor to be called too many times. So don't do it.

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

use vectors instead of rolling your own linked list, unless of course your instructor says you must code your own. But yes, the overload < operator could be used to construct a linked list in sorted order.

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

Create another private function init() (or some other name) that can be called from all constructors

class MyFileExtractor{
public:
    MyFileExtractor(string str) 
    {
       const int STD_NUMBER_OF_COLMS = 1;   //standard number of columns
        init(str,STD_NUMBER_OF_COLMS);
    }
    MyFileExtractor(string str, int n)
    {
        init(str,n);
    }
    ~MyFileExtractor() {cout << "Destructor " << name << "\n"; }
    
private:
    void init(string str, int n)
    {
        name = str;
        columns = n;
    }
   string name;
   int columns;
}

The output is this:

Destructor zn65.dat
Destructor co60.txt
Press any key to continue . . .
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I think that will work.

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

Looking at that static method some more, I think what you really want is a vector of Customer objects.

int main()
{
     vector<Customer> customers;

       for (int i=0;i<n;i++){
            Customer c;
            stringstream s;
            s << i;     
            c.set_id(i);
            c.set_name("name" + s.str());
            c.set_surname("surname" + s.str());
            c.set_addres("address" + s.str());
            customers.push_back(c);
        }

   ...
   ...
   vector<Customer>::iterator it;
   for(it = customers.begin(); it != customers.end(); it++)
         *it->display();
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Plus, the whole static create customers thing just seems wrong to me.

I agree -- it would be better to allocate an array of Customer objects than to have one object allocate an array of data within that instance

int main(int argc, char** argv) {
    int n=10;
    Customer* customers = new Customer[n];
    for (int i=0;i<n;i++){
        customers[i].display();
    }
delete[] customers;
}

The class should also use std::string instead of char* because (1) its c++ instead of c, and (2) your program doesn't have to worry about memory allocation/deletion.

class Customer{
private:
    int id;
    std::string name;
    std::string surname;
    std::string address;
public:
    Customer(){
        this->id = 0;
    }
    void set_id(int id_){this->id = id_;}
    void set_name(std::string name_){this->name = name;}
    void set_surname(std::string surname_){this->surname = surname;}
    void set_addres(std::string address_){this->address = address;}
    int     get_id(){return this->id;}
    std::string get_name(){return this->name;}
    std::string get_surname(){return this->surname;}
    std::string get_address(){return this->address;}
    void display(){
        cout<<"********Customer Info*********\n";
        cout<<"ID........:"<<this->get_id()<<endl;
        cout<<"Name......:"<<this->get_name()<<endl;
        cout<<"Surname...:"<<this->get_surname()<<endl;
        cout<<"Address...:"<<this->get_address()<<endl;
    }
    ~Customer(){
      // nothing to do
    }
    // delete the static method because its not needed.
};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I'm not certain which functions you mean. The two friend functions?

With the below you have to write the two friend functions so that they read/write the class's data objects from/to data file. That's called serializing (don't ask me why it has such a wierd name because I don't know).

int main()
{
     Contributor Jerry;

     ifstream in("infile.txt");
     infile >> Jerry;

     ofstream out("infile.txt");
     outfile << Jerry;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you had it backwards file >> "4l@3";

Alex Edwards commented: Lot's of patience and grand advice! +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you're on windows, a common way to do it is system("PAUSE"); . It gives a prompt like "Press any key to continue..."

Why you should not use that.

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

>> line 32 is an encryption btw
Doesn't matter because its still wrong.

You have that last remaining error because you didn't include the { and } correctly. See below.

I get a clean compile with this (vc++ 2008 express). I commented out that bad line near the bottom of the program.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void ItemID();
void ItemID1();
string ItemIDd;


int main()
{
    ItemID();
}
void ItemID()
{
    cout << "Enter the Item ID: \n";
    cin >> ItemIDd;
    ofstream file;
    file.open((ItemIDd + ".asw").c_str());
    file.close();
    ItemID1();
}

  void ItemID1()
  {
    cout << "Enter 1st Digit of the Item ID: \n";
    string ItemID1;
    cin >> ItemID1;

    if (ItemID1 == "1")
    {
        ofstream file;
        file.open((ItemIDd + ".asw").c_str());
     //   "*&^@" >> file;
        file.close();
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

That's kind of an ambiguous question, but here is some discussion of the topic.

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

>>if ((Name,Donation,Sex,IDKey)==(rhs.Name,rhs.Donation,rhs.Sex,rhs.IDKey))

In operator ==. You don't construct if statements like that if( (Name == rhs.Name) && (Donation == rhs.Donation) && // you get the idea?

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

>>Contributor (string Name, double Donation =0.0, gender sex=none, int IDKey=0);

>>Jerry = new Contributor(Jerry,500.00,male,1);

What you are passing in main() is a pointer to a Conmtributor object (named Jerry). What it wants is a std::string that contains the name of a person, for example put quotes around Jerry in the first parameter Jerry = new Contributor("Jerry",500.00,male,1);

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

you forgot to include <string> header file.

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

you have to add something before the return 0 to make the program stop. like this:

#include <iostream>

using namespace std;

int main ()
{
  cout << "Hello World! ";
  cout << "I'm a C++ program";
  cin.get(); 
  return 0;
}

There are several other ways to do it too -- all of them are correct.

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

I got a lot of errors on that code. example: line 16: ItemIDd was not declared.

line 26: you can't name a variable with the same name as a function. Name the variable on line 26 something else.

line 32: what the hell is that????

lines 29-33: you need to surround it with { and } if you want all those statements inside the if clause. Put a { after line 29 and a } after line 33.

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

I had a Ford pinto stationwagon -- the only problem I had with it was that it had no zip, it took a looooong time for it go go from 0 to 50, a snale could beat it.

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

works fine for me, so it must be something else you've done. try posting all the code.

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

>>ItemIDd
That's misspelled.