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

No, Dave, it should be this:

if ( studentid == student[0].id )
Dave Sinkula commented: D'oh! Thanks. +15
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

>>I am using Dev Cpp for dos programming
No you are not. MS-DOS died 10 years ago. What you mean is that you are doing console programming.

If you want nice looking gui menus and mouse support something like what you have in your browser then you have to learn win32 api programming, or use some C wrapper classes such as wxWindows libraries.

You can use mouse in console programs if you use the Microsoft console api functions. Click here

Salem commented: Indeed it is. +18
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

you need to code it something like this -- it has to call fgets() for every line in the file. fgets() only reads one line of the file, not an array of lines.

while( fgets(buf, sizeof(buf), fp) != NULL)
{
   // now do something with this line
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The code you posted has several compiler errors that you need to fix, such as lines 76, 79 and 80.

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

>>but I don't think a new book is in order is it?
What you have is a book about C++ programming. Finish studying that book before attempting something more advanced such as MS-Windows programming. You should do all the exercises at the end of each chapter to insure you understand the material covered.

When you have finished that book you will probably be ready for a book about MS-Windows programming. Windows programming is not another language -- its still C and C++, but it has a lot of new concepts and techniques you need to learn.

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 are probably reading the wrong book. You need to buy a book about MS-Windows programming. And yes, it is not for beginners, you need a good basic understanding of C or C++ languages.

You can save yourself some time with this intoduction tutorial. It is by all means not complete -- it only introduces you to a few concepts.

>>My current book doesn't even have "STARTINFO" or "PROCESS_INFORMATION
Look up CreateProcess at www.microsoft.com. Just enter that in its search box and it will give you several links. That link will describe those structures.

Alex Edwards commented: Nice post =) +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

What you should have coded is an array of 5 STUDENT structures. Each structure holds the information for just one student

typedef struct
	   {
	    int  id[5];
	    char* name;
	    int quiz1;
	    int quiz2;
	    int quiz3;
	    int quiz4;
	    int exam;
	   } STUDENT;
int main()
{
    STUDENT students[5];

//	Statements
	student[0].id = 1234;
	student[1].id = 2134;
	student[2].id = 3124;
	student[3].id = 4532;
	student[4].id = 4678;


}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
cout << "Enter a number. " << endl;
cin >> number;

Enter the number of what? Are you supposed to enter the number of quarters, or the number of dimes, or the number of whole dollars ? or what? Since number is an integer you can't enter something like $1.25 because integers don't have fractions, they are only whole numbers. So if you want number to be the number of quarters then you would have to enter 5, which is 5 quarters = $1.25. If you want number to be the number of nickels then you would have to enter 25 because there are 25 nickles in 1.25.

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

>>in the code work, or do I have to do something to it? That is the formula, and i was tryng to make it work with the cod
Yes, you will have to modify it to make them legal c or c++ statements.

First, you have to know the kind of units you will enter -- are you going to start with X number of quarters ? or something else ?

>>if (pennies = 0) || (nickels = 0) || (dimes = 0)
You used the wrong operator, = is an assignment operator, and == is a boolean operator. So it should be if (pennies == 0) || (nickels == 0) || (dimes == 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

I was just kidding. :) Dani is probably the only one who can answer your question.

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

What operating system? Under MS-Windows you can't achieve that goal with the system() function because it doesn't return anything about the process that was started -- steam.exe in your example post. Instead, use win32 api function CreateProcess(). The last parameter will be filled in with the information you need to pass that process messages, such as dumping keystrokes into its keyboard buffer.

STARTINFO sinfo;
PROCESS_INFORMATION pinfo;
memset(&sinfo, 0, sizeof(STARTINFO);
sinfo.cb = sizeof(STARTINFO);
BOOL bVal = CreateProcess(NULL, 
          "C:/Program Files/Steam/steam.exe",0,0,0,0,0,0,&sinfo, &pinfo);

Be sure to initialize the STARTINFO structure as shown above because if you don't CreateProcess() will probably fail.

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

And what is the problem with that message? If you want 52 seconds you will be ok, right?

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

Did you try to use a different name? Is filename a reserved word in FORTRAN (and is FORTRAN case-insensitive) ?

Also, did you make the C function the correct calling convention for FORTRAN? Here are the available options.

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

Thread closed. You all should communicate somewhere else.

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

It may be old joke, but its still funny, especially to those who have never seen it before.

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

Welcome to DaniWeb where you will find several of us old dinosaurs :) As for your question, please post on one of the Tech Talk boards.

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

Welcome to DaniWeb. Sorry but I had to cut out your email -- against the rules to post them.

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

Welcome to DaniWeb. See these links

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

How about where did the phrase computer bug come from?

True story -- September 1947, Grace Hooper at Harvard University.

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

Welcome to the crowd. Being one of us may not be as bad as you fear. Assuming that you'll know how to select the good advice from this thread and reject the junk that sometimes appears here, you'll be a welcome addition to us "oldies" and make us proud to have you in our ranks.

I agree -- now I have time to do all those things on my wife's "honey-do list", and we have a lot more time to do things together that we didn't have before I retired.

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

Well, its not quite as easy as what I posted, there is code that I omitted. Also it may be more complex depending on the class objects, such as pointers, other classes, etc.

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

My guess is that MS-Windows treats pen events just like mouse events -- there is no difference between the two.

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

Hi,
I want the difference between procedural programming language and opps languages with beautiful example
,

I think you are confusing terms -- oops is not the opposite of a procedural language. An "event driven" language is the opposite of procedural.

procedural: the program executed from top down with loops to redirect it. Most console programs are procedural programs.

event driven: The program executes a piece of code when some event happens, such as when you type on a keyboard, click a button, or select a menu. All MS-Windows GUI programs are event driven programs.

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

On client, send the object just like you would send any other blob, then on client recreate it from the blob. Probably something like below. Make sure the class has an overloaded = operator for this to work.

// server
MyClass object;
...
send(socketID, &object, sizeof(MyClass));
// client
// this isn't going to be technically accurate, but gives you the idea.
unsigned char* buf = recv(sucketID);
MyObject object = *(MyObject*)buf;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Very creative :)

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

I've had lots of those wow moments -- especially after a few drinks of alcohol. Warning! alcohol and coding don't mix :)

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

you can also do it like this:

char inbuf[255];
// allocate array of 10 pointers and initialize them all to 0
char* pString[10] = {0};
int i;

for(i = 0; i < 10 && fgets(inbuf, sizeof(inbuf), spIn+i)
{
    // allocate memory for the string
    pString[i] = malloc(strlen(inbuf+1);
    // copy the string to the pString array
    strcpy(pString[i], inbuf);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Does anyone have earned bigbucks in PPC? I really need to earn money today.

So get off your duff and get a paid job.

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

If you want help then you will have to post code. I'm getting old and my eyes can't see as good as they used to so I can't see your monitor from where I'm sitting. I never owned a crystle ball either. :)

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

I have no idea what you want! A program that shows its input data is garbage? What kind of statement is that supposed to be???

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

>>f.write(str_name.GetBuffer(str_name.GetLength()),str_name.GetLength());

This will not help the problem you describe, but you should be using the >> operator for that, not the binary write() function. f << (LPCTSTR)str_name << "\n"; Note that you don't need to call GetBuffer() because CString has overloaded the LPCTSTR operator that does similar thing -- when you use GetBuffer() you also should call ReleaseBuffer().

How much text are you attempting to add to one line of the ComboBox anyway? Maybe what you want is a list box which will show larger amount of text for each item.

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

>>or maybe i should just remove the '&', but thought it's a good practice to pass reference params

Don't remove the & because open streams must be passed by reference.

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

cin wants a reference to an integer, and getDay() just returns an int. If you change getDay() to return a reference then readDate() should work correctly. Example:

class Date
{
...
    int& getDay() {return m_day;}
};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

What happens when you try it buddy??

I just got the Page Not Found error message. I've tried it sense then and it worked ok.

I only tried right hand and got only moderate rating -- that's probably because I rarely play games or because my fingers are slowing down. When they stop moving I guess I'll have to quit DaniWeb :)

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

Welcome to DaniWeb.

>> I have done my very best to keep grammar and punctuation at a proper level
In that case you have done a lot more than most of us. Don't worry too much about grammer, few, if any of us, are English majors in college. We don't expect perfection here because there are many members whose native language is not English.

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