mitrmkar 1,056 Posting Virtuoso

Yeah, that helps, but I still want to know for my next programs, what to do if the text IS interactive...

You can try to resort to the SetConsoleScreenBufferSize() function, as suggested by nezachem. It is actually quite simple, so maybe try running the below code and see how it works.

#include <stdio.h>
#include <windows.h>

int main(int argc, char *argv[])
{
  /* Initialize the screen buffer info to zero */
  CONSOLE_SCREEN_BUFFER_INFO info = {0};

  /* You need the console's std output handle */
  HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);

  if(hStdOut == INVALID_HANDLE_VALUE)
  {
    /* No luck */
    printf("GetStdHandle() failed, error: %lu\n", GetLastError());
    return 0;
  }

  /* Get the current settings ... */
  if( ! GetConsoleScreenBufferInfo(hStdOut, &info))
  {
    /* No luck */
    printf("GetConsoleScreenBufferInfo() failed, error: %lu\n",
        GetLastError());
    return 0;
  }

  /* Adjust this to your likings, info.dwSize.Y is a SHORT, 
   * so, keep within the limits of a SHORT.
   * SHRT_MAX is defined in <limits.h>
   */
  info.dwSize.Y = SHRT_MAX - 1;

  /* Interestingly, seems that SHRT_MAX - 1 is the maximum
   * working value instead of SHRT_MAX.
   */

  /* Apply your new settings ... */
  if( ! SetConsoleScreenBufferSize(hStdOut, info.dwSize))
  {
    /* No luck */
    printf("SetConsoleScreenBufferSize() failed, error: %lu\n",
        GetLastError());
    return 0;    
  }

  /* Print lines up to the maximum, once finished,
   * you should still be able to see the first line printed.
   */
  for(int ii = 0; ii < info.dwSize.Y; ++ii)
  {
    printf("\nline# %d", ii);
  }

  getchar();

  return 0;
}

If you want to increase the number of characters that fit …

mitrmkar 1,056 Posting Virtuoso

No it's not. The system in our education gives the teacher the free will to do whatever he may see as good to go, so I think it was his choice to work with this old resources and not give us the up-to-date programming methods in C++.

Somewhat hard to believe but I take your word for it.

mitrmkar 1,056 Posting Virtuoso

You mean the highlighted line that the program highlights it as an error? Well, it's line no. 13, and I don't think that it needs a semicolon.

Yes you are right, in general depending on the compiler and the error, sometimes the error message points you straight to the line that needs fixing, sometimes not. If not, then there are error(s) preceding the offending line.

The problem that there is, is that the function definition ends with a semicolon and that is plain wrong. Function declarations/prototypes need to end with a semicolon but definitions not. So, just remove the extra semicolon there (in this case line #12, I think).

mitrmkar 1,056 Posting Virtuoso

Yeah the grumpy kind of teacher, you know.

I meant to say, that this problem is in the educational system/resources, so your teacher is probably quite restricted by that.
If he's grumpy, that's another thing you have to live with.

mitrmkar 1,056 Posting Virtuoso

What's an offending line ? :?:

The source code line that gives you trouble.

mitrmkar 1,056 Posting Virtuoso

I have a weird teacher : (

Last time he saw me writing the program in Visual Studio with <iostream> and "using namespace std" instead of <iostream.h> he told me to use Turbo C++ to follow up the leasons just like he gives it to us. The old 93 way I guess.

Well, your teacher is bound to his rules and regulations and other things alike, I would assume.

mitrmkar 1,056 Posting Virtuoso

I think it goes something like this:

#include <iostream.h>
void sum( int *a, int *b, int *c);
int main()
{
int x,y,z;
x=12;
y=8;
sum(&x,&y,&z);
cout<<"sum:"<<z<<endl;
return(0);
}
void sum( int *a, int *b);
{
*a=*a+1;
*b=*b+1;
*c= *a + *b;
}

But I still have the same error.

There is one extraneous semicolon on the offending line ;)

mitrmkar 1,056 Posting Virtuoso

Yet one more thing, if/when you do strcpy(argv2, argv[1]); you want to check that there actually is an argument available, you can use argc for that.

mitrmkar 1,056 Posting Virtuoso

Error NONAME00.CPP 13: Declaration terminated incorrectly

A semicolon is missing *c= *a + *b; And you could also clearly state that main() returns an int . So rather make it ..

int main()
mitrmkar 1,056 Posting Virtuoso

Still got 1 error.

Tell us what the error is ...

[EDIT]
To be more clear; tell us the compiler error message, if you are receiving one.

mitrmkar 1,056 Posting Virtuoso

Oh, jonsca was fast, so I reduce this reply to state just the following:
A void function does not return anything. So it is an error to try to assign the function's return value to anything because there is no return value.

So you are supposed to use the function as

// Call the function (with existing arguments)..
sum(&x,&y,&z);
// .. now it's done the calculation, see what you got
cout << "sum: " = z << endl;
mitrmkar 1,056 Posting Virtuoso

What tkud already said ^^ and also if you can describe what's the purpose of this program and the red dot, then people might come up with suggestions.

mitrmkar 1,056 Posting Virtuoso

Change the function's return type to void and pass the third argument also as a pointer. (Though this first version that you have is more 'natural'/usable, i.e. it returns the calculated value.)

mitrmkar 1,056 Posting Virtuoso

About the access violations, in Queue::dequeue() and Queue::front() you have to watch out for first being a NULL pointer. Now you end up accessing the member variables through a NULL pointer, giving the access violations.

Then ..

int num_Serv;
cin >> num_Serv;
// In C++ you cannot have variable length arrays like this,
// i.e. num_Serv is not a constant known at compile time
Teller_s tellArray[num_Serv]; // Wrong

So maybe allocate dynamically ..

Teller_s * tellArray = new Teller_s[num_Serv];
// .. and when you are done with the tellers
delete [] tellArray;

abhi_elementx already pointed out that the following is not quite right ..

if (bankQ.front() != NULL) {

That is because front() returns ElementType instead of a NodePointer . You might want to use something like is_empty() there.

Always initialize your variables, now at start-up, runAgain contains whatever value there happens to be ..

char runAgain;
while (runAgain != 'N') {
// Code is executing here with pure luck ..

Don't leak memory, that is, remember to delete the Node s that you've allocated.

There may be other things too, but if you fix what's mentioned above, you'll be making some progress and can concentrate more on the actual simulation.

mitrmkar 1,056 Posting Virtuoso

Basically I'm asking how I can output pixels to the screen without using any of the default windows gui classes.

It seems that you might want to create and use your own windows classes. Perhaps start by reading about Window Classes.

Or if you really just want to simply output pixels on the screen, then see SetPixel Function.

mitrmkar 1,056 Posting Virtuoso

Also, I am having a hard time remembering how to make so I can use a function that is further down the program. Instead of it saying it is undefined

You need the function prototype prior to its usage and the function definition later on.

// The prototype
int some_func();

int main()
{
  int xyz = some_func();
...
}
// The definition
int some_func()
{
  return 42;
}
mitrmkar 1,056 Posting Virtuoso

This looks like undefined behaviour

7.1.6.1

Except that any class member declared mutable (7.1.1) can be modified, any attempt to modify a const object during its lifetime (3.8) results in undefined behavior. Example:

<snip>

const int * ciq = new const int(3); // initialized as required
int * iq = const_cast<int*>(ciq); // cast required
*iq = 4; // undefined, modifies a const object

nezachem commented: Right, thank you. +1
mitrmkar 1,056 Posting Virtuoso

Yes it does. But when I opened the thread at around 3:12 the other posts weren't there. Then I got called away and finished my post at 3:37.

LOL, a nice mix-up.

mitrmkar 1,056 Posting Virtuoso

You need to test the return from cin and look for EOF

Am I missing something (big time), or isn't that just what

if(cin.eof())

does?

mitrmkar 1,056 Posting Virtuoso

When cin encounters Ctrl-Z, cin.eof() will return true. So e.g.

if(cin.eof())
{
  cout << "bye ...";
  return 0;
}
mitrmkar 1,056 Posting Virtuoso

Have you thought about forgetting the char arrays and using std::string instead? Consider for example

// Read in the line from data.txt, in one go
string line;
ifstream ifs("data.txt", ios::in | ios::binary);
if(getline(ifs, line))
{
  cout << "read: " << line << endl;
}

But if you insist on using char arrays, then fix the first strcat() by replacing it with strcpy() , so ..

char argv2[ <a reasonably large value here > ]; //will store argv[1] (path)
strcpy(argv2,argv[1]);

The way you have it, is definitely wrong, argv2 is uninitialized there and the strcat() is likely to end up trashing memory.

At any rate, be prepared for paths longer than 80 chars, a reasonable max path length would be 260 chars (which is MAX_PATH on Windows).

mitrmkar 1,056 Posting Virtuoso

"error: switch quantity not an integer"

The token is a std::string , so it cannot be used as such in a switch()/case . But by looking at your current code, you want to do ..

switch( token [ 0 ] )
{
case '+' : value = value2+value1; break;
...

About atoi() , you might be better off using a stringstream for converting the input to a number.
Daniweb surely has many examples of doing that.

mitrmkar 1,056 Posting Virtuoso

In need a simple code that will check if proccesname is running, and if it does it terminate the c++ exefile, but if it dont it will continue to the code i want to run, can this be done?

You might state the operating system that you are running.

mitrmkar 1,056 Posting Virtuoso

You might post the code that is not working (?).

Aia commented: That would have been the smart thing to do, you would think. +8
mitrmkar 1,056 Posting Virtuoso

Now, the problem I am facing is that when I read the file, I am shown the value two times.

Simply don't use .eof() in the loop control, it does not work as you may think it does. Rather do..

while (fr.read((char *) &s, sizeof s))
{
  printf(...);
}

Maybe see Why does my input seem to process past the end of file?

mitrmkar 1,056 Posting Virtuoso

So is there any memory leak in
bool CManager::GenerateResponseTagMap() ??

It looks like a perfectly valid way of doing what you are doing there. However, you may be leaking CManager object(s). So, how are you allocating those objects, also are you using static CManager objects?

mitrmkar 1,056 Posting Virtuoso

How about by-passing the CString here, and printf() 'ing the number directly, so,

// Somewhere you probably have ..
int the_number;
// .. and then output it ..
printf("!64.8 Px.1= %d", the_number);

If that's not an option, then you have to parse the data string to get the number.

mitrmkar 1,056 Posting Virtuoso

Class Parser and in this class is constructor

Parser(string s){ // constructor
}

Parser constructor takes a temporary string, i.e. once the Parser object is constructed, the string s object is destructed, hence tokens ends up pointing to deleted memory (i.e. garbage).
You might pass the string in by reference, in which case tokens would be usable as long as the external string exists. Or have a new string member variable that takes a copy of the passed-in string (that would be safe).

mitrmkar 1,056 Posting Virtuoso

CString::Format() works like sprintf() , so you can do ..

CString data; 
CString data2 = _T("1200");

data.Format(_T("!64.8 Px.1= %s"), (LPCTSTR)data2);
mitrmkar 1,056 Posting Virtuoso
BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)

I know what a bool type is, it means that in case the dialog box, dosn't work, it returns false, and displays the error message.

See DialogProc Function

Seems that you already figured the rest out by yourself - good.

mitrmkar 1,056 Posting Virtuoso

undefined reference to `AboutDlgProc(HWND__*, unsigned int, unsigned int, long)@16'
ld returned 1 exit status

This is what i have at the "top" of the main.cpp

BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);

Now that you have declared the function, the next step is to implement it too, that is, you have to write the code for the AboutDlgProc() function (most likely in the main.cpp file).

I'm assuming that you are compiling some example project?

pato wlmc commented: Thanks, man you helped me alot +0
mitrmkar 1,056 Posting Virtuoso

Perhaps you might start by looking into GetFileSecurity Function. And from there on try to figure out the relevant parts of the Windows authorization.

mitrmkar 1,056 Posting Virtuoso

AboutDlgProc is the dialog procedure (a function) that will handle displaying your About dialog box. The compiler has not seen the AboutDlgProc() function at the point where the error occurs.

Do you have that function in that .cpp file?

mitrmkar 1,056 Posting Virtuoso

anyone? How do you load in values to a variable?

If you add the following cout << there

while( getInput(infile, ID, Sales) )
{
  cout << "ID:\t" << ID << "\tSales:\t" << Sales << endl;
  displayResults(outfile, ID, Sales);
}

What is the output on your screen?

mitrmkar 1,056 Posting Virtuoso

"no match for operator<' in' i<token' "

for(i=0;i < token; i++)

'push' undeclared

push(token[i]);

'pop' undeclared

value1 = pop( );

I think you meant to say ..

for(i=0;i < token.length(); i++)

And for the other two errors, both pop() and push() are methods of the Stack class hence you need an instance of the Stack class in main() . So it would be ..

Stack stk;
stk.push();
stk.pop();
mitrmkar 1,056 Posting Virtuoso

It is more than just to get the pthread_create() syntax right. How about taking some time and going through pthread tutorial(s)

Salem commented: Indeed! +19
mitrmkar 1,056 Posting Virtuoso

hte above code reads from the file a word of max length 15 and puts it into the string a. The line: f>>a, tells the compiler to read from file till a white space is encountered.
For more info, go to:
http://www.bgsu.edu/departments/compsci/docs/read.html

That is actually an example of a bad way to read input (and that is also explained on the page you linked).
The page says ...

In the second example, the programmer made a mistake since the string has only space for 10 characters, but the computer would continue reading up to the letter 'p'. The actual output in this situation would depend on the computer used.

mitrmkar 1,056 Posting Virtuoso

>>I get quite a ew warnings around 76 ..
Choice to ignore warnings is all yours (I hope you do know what you are doing though).

I'd would assume some sort of VS failure, in terms of building a proper binary, but then again who knows.

mitrmkar 1,056 Posting Virtuoso

Hmm, main is without parenthesis there, so I assume that you just typed that piece of code as an example, instead of copying it from the program's code.

Increase the warning level to the highest (W4) and rebuild the project. What does the compiler say?

mitrmkar 1,056 Posting Virtuoso

'this' is always a pointer, so e.g. this.Year is wrong, it has to be this->Year . operator <() is 'const', that means that every class method you call inside it, must also be 'const', in this case it means getMonthInt() . Then again, you might directly access the .Month member variable.

To avoid unnecessary temporary objects, consider passing rhs by reference, i.e.

bool Date::operator<(const Date & rhs) const;
mitrmkar 1,056 Posting Virtuoso

Is your code using assert() or any of the VS macros wrapped around assert() ?
Furthermore, have you written e.g.

#ifdef _DEBUG
.. do something here ..
#endif

If you have, then make absolutely sure that you are not changing anything via those pieces of code.

mitrmkar 1,056 Posting Virtuoso

Please forget missing library files, as a matter of fact, what do you actually mean by missing library files?

The only way that it seems to run succesfully (that is, without crashing), is to have it read an empty input file.

[EDIT]
What compiler are you using ..

- at school:
- at home:

mitrmkar 1,056 Posting Virtuoso

Apparently you want to return a reference, like so

friend std::ostream & operator<<(std::ostream& os, const u_string& uStr);
// and
std::ostream & operator<<(std::ostream& os, const u_string& uStr) {
os<<uStr.str;
return os;
}
mitrmkar 1,056 Posting Virtuoso

How do I use the STL stack implementation with pointers to my TreeNode class?

You had a stack of TreeNode objects, not pointers to such. So ..

stack<TreeNode * > s; 

TreeNode * a = new TreeNode(val);
s.push(a);
mitrmkar 1,056 Posting Virtuoso

Hey,
can someone tell me where I have to start?
I wanna make a program like cheat engine but I have no clue how :o...
Im not a beginner ( but also not an expert :P ) in C++(/CLI)...

What functions do I need?
etc. :p

Thx ;D

Mmmm, at the very least

int main()
{

}

;)

mitrmkar 1,056 Posting Virtuoso

Most likely GCC is unable to locate <stdarg.h>, just like <stddef.h> in your other thread. Something is wrong/misconfigured/missing with your setup/environment - that's all I can think of.
Have you tried to locate these files on your computer?
Try passing the -v option to GCC so that you get to see where it is looking for files.

mitrmkar 1,056 Posting Virtuoso

In addition to what's been already stated. Only focusing on a very basic thing.

This basic thing here is that you try to delete memory that was never allocated in the first place. In other words, you do delete string without having allocated any memory to string and string is uninitialized at the point of deletion.

Try debugging the following code step-by-step, and you'll see how it goes wrong in the assignstring() method.

int main()
{
  String oops("ouch");
}

So, one basic thing for you to do, is to figure out how to protect the code from this kind of crashing (hint: it's about initializing variables prior to their usage).

PS. If you do new some_thing[some_size]; then you must delete [] some_thing; or else your program leaks memory.

mitrmkar 1,056 Posting Virtuoso

Try specifying the full path to the .ico file, like

hIcon = (HICON) LoadImage(NULL, "c:\\full\\path\\to\\menu_two.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE);

GetLastError() gives you an error code that might be helpful when figuring out the reason of a failing Win API call. See an example of
Retrieving the Last-Error Code

mitrmkar 1,056 Posting Virtuoso

warning C4700: local variable 'myInstructions' used without having been initialized

Consider these warnings as errors actually. If you don't fix these warnings (all of them), you will be in for surprises. And in general, pay attention to the compiler warnings, and don't ignore them.

mitrmkar 1,056 Posting Virtuoso