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

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

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

In c++ they are the same.

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

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

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

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

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

I think that will work.

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

>>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 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

>> char* inputFileName=argv[100];
Huh? Do you pass over 100 arguments on the command line to your program? Not very likely, so that are you trying to do here ?

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

Just use normal file i/o streams such as ifstream and ofstream. If you want to display the usual OpenFile dialog box that lets you select the file you want to open then call GetOpenFileName()

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

You can do it either way -- include <vector> in the *.cpp file before including car.h, or just add <vector> at the top of car.h. Either way works.

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

you probably forgot to include <vector> header file.

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

>>MoveFile(argv[0], KEY);
That will always fail because you can not move a currently running program, and argv[0] contains the name of the program you are writing.

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

what operating system and compiler are you using? Do you mean the version in my last link? If not, then provide link to it because there is no standard C or C++ library function.

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

So you mean this function ?

>>s any way to solve this?
Yes, fix the bug in your program.

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

MFC only comes with the Standard or better version of the compiler. The Express version doesn't support it.

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

Ironically, the Pope also said in Austrailia

"Our world has grown weary of greed, exploitation and division, of the tedium of false idols and piecemeal responses, and the pain of false promises," he told the crowd.

On the one had he complains about the falling US dollar, but denounces money as false idols.

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

>> 8.5million long array
I already answered that -- and the answer is yes.

>>add/remove arrays from the 8.5million
Easy to do with vector class, but it might be a little slow because of the magnitude of the array. Maybe std::list (a linked list) would be more suitable because the insertion and deletion time is constant while vector is not constant.

>>break up arrays into single variables
If you use a vector<int> then you don't need to do the above because they're already individual variables.

Here the proof that it works in c++: Compile and run this with your c++ 32-bit compiler to see for yourself.

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

int main()
{
    const int maxsize = 8500000;
   vector<int> lst;
   lst.resize(maxsize);
   for(int i = 0; i < maxsize; i++)
       lst[i] = i;
   cout << "done\n";
    cin.get();
}
OmniX commented: Thankyou for the help and information +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You can change the compiler's padding behavior by using some options or pragmas. Microsoft compilers can eliminate padding altogether with

#pragma pack(0) // don't pad this structure
typedef struct
{
   // blabla
}
#pragma pack() // revert to default padding

Deleting padding is useful when you want to save data in binary form to a file or xmit it across socket and you don't know what is on the other end. It will also help reduce memory requirements in some applications which use large arrays of those structures.

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

you have 8.5 million array of what type? integers, floats, strings, or what. You have to declare the data type when you declare the array in c/c++.

How do you get the data for that array? Read the number from a data file, get them from SQL database, or something else?

Without knowing exactly what you are attempting to do I can't give you much more help or suggestions.

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

>> PS: C vs. C++ whats difference?

see these google links.

>>what should I use?
Its up to you, but I would use c++ because you can use c++ container classes like vector that does all the dynamic memory allocation for you. You can easily add, subtract, and sort vector array elements without worrying about how to do it.

But I suspect you need to rethink what you want to do. 8.5 million array elements is very unusual. Do you really need an array that huge? Is there another way to do what you want without that large an array?

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

>>Now I havent tried this yet BUT I dont think php will let me make a 8.5 million length array nor will C++.

Depends on the C++ compiler -- most (all) 32-bit compilers will do it but no 16-bit compiler such as Turbo C. An array of 8.5 million integers consumes 8500000 * sizeof(int) = 34,000,000 bytes, or roughly 32 meg.

>>PS: Best programming language is C++, correct?
depends on what you want to do. assembly might be the best for some solutions.

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

That clears up a lot -- except the part about the professor sprayhing some ants.

int main()
{
    const int AntsStompedPerMinute = 10000;

    int ants, yards;
    ifstream in("datafile.txt");
    if(!in.is_open())
    {
        cout << "Can't open input file\n";
        return 1;
    }
    while( in >> ants >> yards)
    {
        int minutes = 0;
        for(int minutes = 0; ants >= 0; minutes++)
        {
            cout << minutes << '\t' << minutes * yards << '\t' << ants << "\n";
            ants -= AntsStompedPerMinute;
        }
        cout << "\n\n";
        cin.get();

    }
    cin.get();
    return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you don't need that while statement in the program. while(inFile >> ants >> yards) will read the file until eof().

I'm completly confused about those simulations. What do you mean by first simulation and second simulation ? Is each line in that data file a different simulation ?

The first line has 50000 ants and 1 yard. What does that mean? 500000 ants moved 1 yard before something kills all the ants? What are you supposed to do with that information ?

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

delete line 30 -- it serves no purpose and will cause infinite loop that that trailing semicolon. Its probably just a left-over from your previous version of the program.

>>but still would not loop till ants = zero
Of course not unless the data file has the value 0 in it. If it does contain a 0, then you can code the while loop like this: while(inFile >> ants >> yards && ants != 0)

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

Note: This really belongs in web site reviews, but since you posted here I'm going to comment here.

aarya: why is freewebschools.com incomplete? I clicked on most of the links and only got "Webpage cannot be found" errors. If you're going to advertise your web sites at least the links should work.

And the tutorials are terrible (only looked at HTML), they are so brief that they are next to useless. I was disappointed because I was hoping for something with a lot more meat to it.

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

you have some lines out-of-order.

1) move line 28 to line 13. You have to open the file before testing if the open failed.

2) exit the program if the open failed. There is no point continuing. So code exit(1) after the error message.

3) Here is how to code that input loop. Delete that do loop and code a while loop like this

while( infile >> ants >> yards)
{

    // do something with the data
}

4) delete lines 59 and 63 -- they not needed. There is no point clearing the flag before closing the file unless you are going to use the same stream object again for something else.

5) lines 47 and 48: What are those two loops supposed to be doing? All they do is destroy the value of the variables that were just read in. And those two loops do nothing because the counter is initialized to 0 then you ask the question if the counter is <= 0. Well, duuuuh! The loop counter is already 0, so the loop will do nothing at all.

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

>>any suggestions ?
New insert function. Note that this version does not use HT[n], but starts at HT[n].link -- simplifies the code.

void insert( int x )
    {
        int loc;

        loc = x % tSize;
		
        Node * tmp2 = 0;
        tmp = HT[loc].link;
        while( tmp )
        {
            if(tmp->data > x)
                break;
            tmp2 = tmp;
            tmp = tmp->link;
        }
        Node *tmp3 = new Node(x);
        if(tmp2 == 0) // insert at head of list
            HT[loc].link = tmp3;
        else if(tmp == 0) // insert at tail
            tmp2->link = tmp3;
        else
        {  // insert somewhere in the middle
            tmp3->link = tmp2->link;
            tmp2->link = tmp3;
        }
        HT[loc].count++;
    } // end function insert
Q8iEnG commented: I don't know how to thank you! :) +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
clock_t t1, t2;

t1 = clock();

run function 1,000,000 times

t2 = clock()

float diff = ((float)t2 - (float)t1) / 1000000.0F;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The best way to do that is to call that function many times then take the average time. For example, start timer, call the function 1,000,000 times, get end timer, (end-start)/1000000 = average. Of course you'll have to use floats for all calculations.

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

>>listView2->SelectedIndices
SelectedIndices is not an integer -- its an array of integers. listBox1->SelectedIndices->Count is probably what you want.

Did you see the example c++ Microsoft code here

Read the comments carefully.

private:
   void FindAllOfMyString( String^ searchString )
   {
      // Set the SelectionMode property of the ListBox to select multiple items.
      listBox1->SelectionMode = SelectionMode::MultiExtended;

      // Set our intial index variable to -1.
      int x = -1;

      // If the search string is empty exit.
      if ( searchString->Length != 0 )
      {
         // Loop through and find each item that matches the search string.
         do
         {

            // Retrieve the item based on the previous index found. Starts with -1 which searches start. 
            x = listBox1->FindString( searchString, x );

            // If no item is found that matches exit.
            if ( x != -1 )
            {
               // Since the FindString loops infinitely, determine if we found first item again and exit.
               if ( listBox1->SelectedIndices->Count > 0 )
               {
                  if ( x == listBox1->SelectedIndices[ 0 ] )
                                    return;
               }

               // Select the item in the ListBox once it is found.
               listBox1->SetSelected( x, true );
            }
         }
         while ( x != -1 );
      }
   }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I guess all of you know this message..
No I don't. Post the exact error message instead of making us guess.

what compiler and os are you using? Learn to use your compiler's debegger so that you can step through the program one line at a time to see its execution.

The only problem I could spot is in main() a data overflow will occur when the value of sum reaches the limit that an integer can hold -- the results of overflow is undetermined.

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

I currently run a Win98 system at my office and am connected on an intranet. Recently we have installed new Xerox Printers which do not support Win98. In an attempt to backdoor this issue with the software/drivers I was unsuccessful. I recall reading some where about a program that could "trick" the software with the drivers to think I am at least running on Win2000.

Any advice would be greatly appreciated.

Thanks,

Mike.

Advice?? Don't be so stingy with your $$$ -- upgrade all computers to XP or Vista then you won't encounter those compatibility issues. Of course you might also have to buy new computers, but then using an old 80x88 is as bad as using horse & buggy on today's super highways.

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

This compiles without error -- did not attempt to run it. I actually got a hint how to do it from the compiler's error message : error C2440: '=' : cannot convert from 'FARPROC' to 'void (__cdecl *)(char *)'

int main(void)
{
 char szMsg[]="Hello, World!";
 HINSTANCE hIns;
 void (*pFn)(char*) = 0; 
 hIns=LoadLibrary("dllWork.dll");
 if(hIns)
 {
    pFn = (void (__cdecl *)(char *))GetProcAddress(hIns,"Prt");
    pFn(szMsg);    
    FreeLibrary(hIns);
 }
 system("PAUSE");
  
 return 0;
}
Unimportant commented: Really no one upvotes this? +4
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

STL does nothing for MS-Windows programming. The intent of STL is portability not anything os-dependent. MFC and STL are not either or situation -- learn both. If I were going to begin a new project today I don't think I would use MFC because there are several other alternatives such as C#, CLR and wxWindows. MFC is a really old class developed by Microsoft as a wrapper for win32 api functions many years before any of those other languages were invented. IMO the only reason to use MFC today is for maintaining old code. If you want to learn MFC, fine, but you should probably concentrate your learning efforts on other previously mentioned languages and wrapper classes.

iamthwee commented: Good advice especially coming from someone who uses MFC +15
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I would write it like this: (this code works only when the power is a positive number)

You are right -- the solution I posted doesn't work for power of 0.

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

>>3^3 = 27.
that's the wrong answer, so you program will never get it (unless the program is wrong) :)

you over-complicated your program -- the solution is much simpler

int byThePower(int number, int power)
{
    if(power >1)
        number = number * byThePower(number,power-1);
    return number;

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

Post what you have tried.

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

You didn't look very hard did you? Click here.

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

Actually, now that I look at your program closer, your program doesn't write anything to those files. In post #5 above, the program opens the file on line 16 and closes it on line 53, never writes anything to it inbetween those two lines. So, somewhere before line 53 you have to add code to write the data to the file. What to write? Look at line 60 -- you have to write those entries (name, course title, id number, dob, and average) to the file. Then after line 59 you have to insert another line or so that reads those same variables from the file. Use fscanf() or fgets() to do that.

raja289 commented: THANKS ALOT FOR UR USEFUL SUGGESTIONS +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Copy/paste what you see on your monitor when you run the program.
here is what I get when I enter 5 students. What is wrong with it?

PROGRESS REPORT

        Rollno          Total           Grade

         100            400             B

         200            374             C

         400            350             C

         300            325             C

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

Please post the error message(s) and line number(s).

WARNING-you may lose significant digits..

Is that it? And on line 97?

If yes, the warning is telling you that temp is an integer and Grades is a character. You can remove the warning by typecasting Grade[j] = (char)temp;