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

As previously mentioned you should not use feof() to control that loop. Here is the correct way. You also have a problem by assuming that each read of the file will read exactly BufLen bytes. That may or may not be true. fread() will return the number of bytes read so you should only send that many bytes.

const int BufLen = 22610;
unsigned char RecvBuf[BufLen];

pFile = fopen ("info.txt" , "r");
unsigned int size = 0;
while( (size = fread (SendBuf , 1 ,sizeof(SendBuf) , pFile)) > 0)
{
        sendto(SendSocket, SendBuf, size ,0, (SOCKADDR *) &RecvAddr,sizeof(RecvAddr));
}
fclose (pFile);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You mean a GUI program? If MS-Windows you have to write a windows program, not a console program. Here is a simple introduction tutorial. It requires a basic knowledge/understanding of C ir C++ language.

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

with your feet :)

That probably means to create a loop and inspect each element. For example:

int array[5];
for(int i = 0; i < 5; i++)
   cout << array[i] << " ";
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Now, since the code in blocks 17-20 are repeated three times you can use a loop

for(int i = 0; i < 3; i++)
{

firstColum = rand() % 2 + 1;
    
    if( firstColum == 1)
    cout << "X";
         else
    cout << "O";

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

lines 20 and 26 are using wrong variable names, so leave them but delete the preceeding calls to srand().

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

>>Is this best solution?
No. srand() should only be called once during the lifetime of the program. Leave lines 12 and 14 but delete lines 18, 20, 24 and 26.

>>#include <conio.h>
That is non-standard function. If you want best solution than delete it.

line 45: delete it. use cin.get() instead.

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

you have to call srand() to generate a new set of numbers - and its only called once at the beginning of the program.

#include <stime>
...
int main()
{
    srand( time(0) );

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

just google for them -- you can even buy degrees without taking one course :)

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

The atmosphere in Vegas is what I find appealing, its not really about the gambling! Posh hotels and restaurants - nice!

prostitutes :) STD :) Nevada (where Los Vegas is) prostitution is legal for any county of less than 400,000 people. That doesn't mean they are clean, only that they MAY BE legal.

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

pipes don't work at all in win32 programs, only console programs on Ms-Windows platforms. See the discussion here for work-around.

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

Is it a joke ?!

No. Did you read the link I posted? MSDN says the first time ShowWindow is called SW_HIDE might be ignored. After that SW_HIDE parameter is honored.

vedmack commented: Helped me, Thx +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

depends on what that function does.

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

The link I gave you IS c++. Download the example and see if you can port it without using MFC. Writing windows programs in pure c/c++ is pretty tough code. It can be done, but its not something beginners can tackle.

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

That tutorial should have shown you how to do it in C#. Look up the C# functions.

I suppose here is one example

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

what are you looking for? Name specific win32 api functions or C# functions.

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

If you travel to Los Vegas make sure you have an unlimited amount of cash :)

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

Try calling ShowWindow twice, according to MSDN the second parameter to ShowWindow() might get ignored the first time it is called. I don't know if it will work, but its worth a try.

HWND hWnd = FindWindow(NULL, sName);
if(hWnd)
{
	ShowWindow(hWnd, SW_HIDE);
	ShowWindow(hWnd, SW_HIDE);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Look up the functions in MSDN. It will often provide C++ examples as well as C#.

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

In that case why don't all 5 of you form a group and do the project as a group? You could each code the part you know how to code. But it might be too late for you all to do that.

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

A fellow mate from class gave me that code, he's been working on. I posted it here to see if it was correct or not.

So, you wanted to hand in some else's piece of crap as your own ?? Don't you think your instructor will notice the resemblence?

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

However he did forget one important thing at the end of his program. :)

return 0;

Nope, I didn't forget it. Its optional. return 0 is the default if nothing is specified. That was a fairly recent addition to the c++ standards so some older compilers may require the return statement.

VernonDozier commented: You are correct. +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

the >> operator first skips all leading space then reads all the characters up to the next space. So if the file contains " Add 5645635654653463546" the >> operator reads Add into the string word. Then the next line the >> operator erases what it in word and reads the next non-space characters into word

It you are still confused maybe you should write a small program to verify what is happening

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

int main()
{
    ifstream in("somename.txt");
    string word;
   in >> word;
   cout << word << "\n";
   in >> word;
   cout << word << "\n";
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I flagged it. I think a mod just added the "cat" part.

Yea, I did -- I hated that title.

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

create an ifstream object and use its >> operator to skip the first word and read the second.

ifstream in("file");
string word;
in >> word; // read "Add"
in >> word; // read the digits
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Hehe thought other things @ first :D (Then realized the staff would hit clicked DELETE THREAD if it was that)

Very nice regardless........

I did just that, then realized what it was about so I undeleted it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
  • Eating ice cream for 24 hours without gaining weight.
  • Learning to play a musical instrument such as piano in 24 hours.
  • Spend the day at a health club without getting too exhausted.
  • Be the President of USA for a day.
  • Fly to UK and spend the day in London.
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't think you can do it by executable name, such as notepad.exe, because the same executable can be running multiple times

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

Now I'm confused about what you are trying to do. I thought you wanted to hide the console window from within the program that is running.

But if you want to write a program that launches another program and hide its window then you can do it with win32 api function CreateProcess(). The lpStartupInfo parameter is a structure and you can set it to disable the console window.

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

>>Now I am on my way to develop C++ using Visual Studio .Net 2003.
Bad idea. Upgrade to VC++ 2008. The Express edition is free for the downloading.


>>Somehow, none of those project recognize the code, I get this error
VC++ uses precompiled headers and the very first include file needs to be stdafx.h

#include "stdafx.h"
// other code here

You can turn off precompiled headers, but I don't know how with VC++ 2003.

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

[edit]On second thought, I don't think below is what you are looking for[/edit]

Here's how to hide the console window

#include <windows.h>

int main()
{
    HWND hWnd = GetConsoleWindow();
    if(hWnd)
        ShowWindow(hWnd, SW_HIDE);

    Sleep(5000);

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

windows and *nix have different implementations so you can't use the same program for both.

For MS-Windows you include <windows.h>. You can use threads by calling CreateThread() in console programs, but I think it will requires a win32 windows program to successfully use the SetTimer() and KillTimer() functions because the program needs an event handling function.

I don't know what you mean by a "polling" mechanism.

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

I would assume the transaction file is in no particular order -- rows are appended to the transaction file as they occur, which can be in any order for any given account.

To update the balance in the master file you will have to read the entire transaction file to find all the transactions for a specific account that's located in the master file. When that is done, rewind the transaction file pointer to beginning of file and move on to the next account in the master file.

That could be a fairly lengthly process if the master file has a lot more accounts than in the transaction file. In that case you might want to reverse the process -- start at the beginning of the transaction file, and for each row locate the row in the master file then update its balance.

If the two files are small enough you can start by reading both files into memory arrays, update the balanaces in memory, then rewrite the entire master file.

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

Its not a bug in your program -- cin >> operator leaves the '\n' in the keyboard buffer and the following getline() stops at the '\n'. So you have to remove the '\n' after the >> operator in order to make getline() work correctly.

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

by making one small change I get this:

Please enter your airline name: stl
Please enter your flight number: 100
Please enter your origin: stl
Please enter your destination: mo
Please enter your departure information: adf
Please enter your arrival information: lkj

Airline: stl
Flight Number: 100
From: stl
To: mo
Departure: adf
Arrival: lkj
Press any key to continue . . .

I added cin.ignore() after line 29 in the *.cpp file.

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

When working with strings you have to convert the entire string, not just a single character. One way to do it is to use the transform() function

#include <algorithm>
#include <string>
...
<snip>
...
std::string inquestion = "Hello World";
// convert to all lower-case
std::transform(inquestion.begin(), inquestion.end(), inquestion.begin(),  tolower);

You will want to also use transform() on each line of the file that is read.

getline(answerfile, answer[m]);
std::transform(answer[m].begin(), answer[m].end(), answer[m].begin(),  tolower);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

What you have posted doesn't tell me a damed thing because all you posted was code snippet. Since I can't read your mind and I can't see your monitor from where I am sitting I guess your next best option is to post all the code.

Also remember that string comparisons are case-sensitive -- that is "World" is not the same as "WORLD". So if you mistype the case of the characters they they will not match. Best thing to do is convert everything to all upper case or lower case then do the comparisons.

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

>>"Mythology"[5] ; is a valid c statment.
Its a do-nothing statement. char c = "Mythology"[5]; is a valid statement.

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

>>and I'm supposed to include an application file, but I don't have the slightest clue by what the professor means by that
The application file is a *.cpp file that contains main(). I would assume from your comment that main() should not be in the same file as the class implementation. So your project would consist of a header file and at least two *.cpp files.

Appears you are mixing up the variables in lines 7-12 of the header file and lines 15-20. Just delete one of the two sets of variables so that it isn't so confusing.

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

Here's an example.

const int max = 255;
int array[max] = {0};
ifstream in("filename.txt");
int i = 0;
while( i < max && in >> array[i] )
   i++;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here is the output I get

<HTML></BODY>Whatever text<BODY></HTML>
You have written 4 brackets; they are:
/HTML
BODY
/BODY
HTML
Off tags are:

Press any key to continue . . .

And here is the code that I modified. I deleted all extern statements because they are not necessary and initialized all data and arrays to 0. The extern statements were the cause of the wierd numbers I found earlier.

#include <stdio.h>
#include <stdlib.h>

#define B_OPEN '<'
#define B_CLOSE '>'
#define BRACKET_MAX 10
#define B_CHAR_MAX 7

char bracket[BRACKET_MAX][B_CHAR_MAX] = {0};
int diagnosis = 0;
signed char bracket_nr = 0, close_nr = 0;


/********************  Prototypes ***********************/
/********************************************************/
/********************************************************/
int push (void);
int writetags (void);



/********************   Main      ***********************/
/********************************************************/
/********************************************************/
int main (void){
//    extern int diagnosis;
//    extern signed char bracket_nr;
    char c = 0;
    bracket_nr=-1;
    diagnosis=0;
    while((c=getchar())!=EOF && c!='\n'){
        if(c==B_OPEN){
        diagnosis=push();
        };
        switch (diagnosis){
        case -3:
             printf("infinate bracket.\n");
             break;
        case -5:
             printf("Too Large Bracket.\n");
             break;
        case -7:
             printf("Too many bracket.\n");
             break;
        
              };
        if (diagnosis < 0)
        break;
        
        
        };
        if(diagnosis==0){
           printf("No brackets.\n");
        
        }else if (diagnosis > 0){
       printf("You have written %d brackets; they are:\n",diagnosis);
       writetags();
       }else{
      printf("Text contains errors.\n");
       
       };
       system ("PAUSE");
       return diagnosis;
       
        
        };
        
        
        
/******************** Push Function**********************/
/********************************************************/
/********************************************************/
        int push (void){
//     extern char bracket [BRACKET_MAX][B_CHAR_MAX];
//     extern int diagnosis;
//     extern signed char bracket_nr;
     char c = 0, bracket_char = 0;
     
     c=getchar();
     bracket_nr++;
     if(bracket_nr>=BRACKET_MAX)
     return (diagnosis = -7); //to many tags
     diagnosis=bracket_nr+1;
     for(bracket_char=0;c!=EOF && c!='\n' && c!=B_CLOSE && bracket_char<B_CHAR_MAX;bracket_char++, c=getchar()){
          //record tag name into the stack bracket …
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

if question is a string array and inquestion is a string, then just use the == operator to compare them

std::string answer[NUM];
std::string inquestion;
<snip>
if (inquestion == answer[theDice])
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

delare the array then fill it from the data that is read from the text file. I'm certain that you know how to do that by now.

int array[255] = {0};
// now read the values from the text file
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You are on the right track. How did you declare those arrays ? And what is inquestion?

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

That's one way to do it, yes.

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

When you call getline() it will return an empty string when there is an empty line.
Example:

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

int main()
{
    string line;
    ifstream in("stdafx.h");
    if( in.is_open() )
    {
        while( getline(in,line) )
        {
            if( line == "")
                cout << "Empty line\n";
        }
    }
            

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

Welcome to DaniWeb. Chicago, the windy city. My brother lives near Chicago. Do you know him :) For those of you who might not know, Chicago is USA's 3d largest city with about 10 million people. Its so tiny I just assumed Wordgunner would know my brother.

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

looks like one problem is the uninitialized variables on line 107. On line 109 you are trying to compare the uninitialized variable with 0. Not a good thing to do. :)

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

look at line 8. It wants an int array and the number of items in the array. In main() you have declared neither.

in main() you need to declare an int array then fill it with some numbers. After that you can call the selection sort function to re-arrange the numbers in either ascending or descending sequence.

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

How about putting the code that works ok into a static library and compile for release. Then the remaining code in the application program which is compiled for debug. Finally link the two.

I suggested the optimize pragma because I don't think the compiler will do stack or bounds checking with it turned on.