mitrmkar 1,056 Posting Virtuoso

>> yeah the compiler says somethign is wrong

I see, could you post the error message?

mitrmkar 1,056 Posting Virtuoso

>> i tried that it doesn't work

So, you are getting a compiler error?

mitrmkar 1,056 Posting Virtuoso

That sounds confusing, I think the following should do ..

#include "Library.h"

//HELPER FUNCTIONS

void Wait()
{
    cout << "Press ENTER to continue\n" ; // <--- added semicolon

    cin.ignore(1);
}
mitrmkar 1,056 Posting Virtuoso

Pass the warning options on the commandline i.e. g++ -Wall -Wextra and first get a clean compile.

As to the surprise number, I believe you might be stepping outside array boundaries, which are 0..N-1, inclusive.

mitrmkar 1,056 Posting Virtuoso

>> error: expected ';' before 'cin'

The compiler seems to be spot-on here, you really need to add a semicolon before cin as suggested.
;)

mitrmkar 1,056 Posting Virtuoso

>> undefined reference to `Wait()'

In Code::Blocks, be sure to add the Helper.cpp file ( Wait() is defined there) to your project and rebuild. Do the same with the file containing Crossroads() .

The compiler is not seeing the definitions of these two functions at the moment.

mitrmkar 1,056 Posting Virtuoso

In ReHeap() , comparison is used instead of assignment ..

if (left < mySize && myArray[left] > myArray[root])
  largest == left; // <--- Wrong

You should catch this by enabling basic warnings, i.e. compiling with e.g. -Wall -Wextra .

Also in ReHeap() , check that left and right are not negative when indexing into the myArray .

mitrmkar 1,056 Posting Virtuoso

>> and these are the erros i get when i try ot compile it:
>> main.cpp:4: error: '::main' must return 'int'

See Should I use void main() or int main()?

mitrmkar 1,056 Posting Virtuoso

Quite likely your project is configured to use precompiled headers through "stdafx.h".
In other words, you'll need to change the order of your includes, in order for the compiler to see <mysql.h>.

You could try ..

#include "stdafx.h" // First stdafx.h

#include <cstdio>
#include <windows.h>
#include <mysql.h>

int main()
{
  MYSQL *conn;
}
jonsca commented: Nice going. +5
mitrmkar 1,056 Posting Virtuoso

>> it seems that the WM_CLOSE message is being sent to my program for some reason.

Your WM_SYSCOMMAND handling needs fixing. As of now, any WM_SYSCOMMAND with wParam not equal to SC_SCREENSAVE or SC_MONITORPOWER falls through to the next case, ending up in a PostQuitMessage (0); call.

mitrmkar 1,056 Posting Virtuoso

There is a stack overflow apparently

To avoid consuming the stack space, make the array global or declare it static .

For example,

/* Statically allocated. */
double array_1[32000];

int main()
{
  /* Statically allocated, only visible inside main(). */
  static double array_2[32000];

  return 0;
}

You may want to see the /STACK linker option.

mitrmkar 1,056 Posting Virtuoso

>> error system was not declared in the scope

If the code involves a call to system(), then you need to #include <cstdlib> .

mitrmkar 1,056 Posting Virtuoso

>> no match for 'operaror!=' in 'user_input!=1'

If you want to retain user_input as std::string , then compare against appropriate string literals, e.g.

if(user_input == "1")
{
  // Option no. 1 selected
}
mitrmkar 1,056 Posting Virtuoso

>> When i put "string user_input;" JUST BEFORE cin>>user_input it will work

Line 8 is effectively a comment because you end line 7 with a backslash (it's called line continuation). So, delete the unwanted backslashes ..

#include <string>
int main()
{
  // declaring variables
  string user_input;
mitrmkar 1,056 Posting Virtuoso

>> Below is the program for swapping variables without any extra variable.

May I suggest that you view for example this thread ;)

jonsca commented: Yes, thanks for pointing that out! +5
mitrmkar 1,056 Posting Virtuoso

>> why this function isn't displaying any results, please?

You initialize shiftAmt to -1 and the loop only executes when shiftAmt >=0 .

mitrmkar 1,056 Posting Virtuoso

>> the compiler screamed at me when I did that.

Sometimes that happens -- anyway, having that period there is certainly wrong. Are you sure there are ..

#include <string>
#include <iomanip>
#include <iostream>
mitrmkar 1,056 Posting Virtuoso

There seems to be an extraneous period there .. cout << setw[B].[/B]((text.length() + lineLength) /2) << text << endl;

mitrmkar 1,056 Posting Virtuoso

There are two glaring errors, namely

delete[] square[i];
// and
free(square);

Simply delete those lines because square is not dynamically allocated -- doing that may fix the program.

Perhaps see Freestore management.

mitrmkar 1,056 Posting Virtuoso

I'm not quite sure what it is that you are exactly asking, but you may get some ideas from the following. Since you already include <windows.h>, you can use the Sleep() Windows API.

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

void print_welcome(void)
{
  printf
  (
    "\n\n\n\n"
    "\t\t   ***************************************\n"
    "\t\t   ***************************************\n"
    "\t\t   ***                                 ***\n"
    "\t\t   ***           WELCOME TO            ***\n"
    "\t\t   ***    CLASS ATTENDANCE SYSTEM      ***\n"
    "\t\t   ***                                 ***\n"
    "\t\t   ***************************************\n"
    "\t\t   ***************************************\n"
    "\n\n"
  );
}

/* Note: It is int main(), NOT void main()! */ 
int main(void)
{
  int i;

  for(i=0; i<5; i++)
  {
    system("cls");
    print_welcome();

    /* Wait for a second */
    Sleep(1000);
  }

  return 0;
}
mitrmkar 1,056 Posting Virtuoso

>> problem is with error handling.. where in the program should not engage in
an endless loop if for example a a letter instead of a number was entered.

See e.g. http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.2

mitrmkar 1,056 Posting Virtuoso

>> After each for each loop, posY should be incremented by 100. So all the boxes should be at the same x position but be 100 pixels(?) apart in the y position.

You missed the point .. incrementing posY has no practical effect in your code w.r.t. positioning the boxes. Try changing to following ..

// Initial values - outside the loop
int posX = 200;
int posY = 200;

for each (DataRow ^row in dataSet->Tables["Contact"]->Rows)
{
	TextBox ^txtBox = gcnew TextBox();
	txtBox->Location = Point(posX, posY);

	posY += 100;
	this->Controls->Add(txtBox);
				
	MessageBox::Show(row->default[0]->ToString());
}
mitrmkar 1,056 Posting Virtuoso

>> My problem is that only one textbox is created on the form. I'm not sure why 3 textboxes aren't being created (because there are 3 rows in the table "Contact").

It looks like the boxes are created on top of each other, i.e. effectively the location of each box is Point(200, 200) .

mitrmkar 1,056 Posting Virtuoso

Good points by Adak.

I'd like to add that, why not simply check what malloc() returns, along the lines of ..

buffer = malloc(VSN_BUF_SIZE + 1);

if(buffer == NULL)
{
  /* Display error message and perhaps exit */
  perror("malloc()");
  exit(EXIT_FAILURE);
}

In case the reason is not an allocation failure, then you might post more code. Preferably a minimal complete example which still fails.

PS. Note that sizeof(char) is guaranteed to yield 1, so using it is redundant.

mitrmkar 1,056 Posting Virtuoso

>> How should I initiate the str_month, I thought that line #12 initiation is sufficient

strncpy() does not necessarily NULL-terminate the string -- so, you might do e.g. ..

str_month[3] = '\0';
mitrmkar 1,056 Posting Virtuoso

>> My rand() isn't very random. As a matter of fact, it's not random at all!
>> I get the same result every time on both computers: 180428383

This is by design, you want to Initialize random number generator.

mitrmkar 1,056 Posting Virtuoso

>> ... tokenize my string, which is read from a file, but my output is blank, why?

There could be many reasons for no output at all - was the file opened, what's in it etc. You could get a bit creative and display what you read from the file ..

while( getline( infile2, temp2 ) )
{
  cout << "read: [" << temp2 << "]" << '\n';
  ...
}

At any rate, in your first snippet, you should remove the return 0; -- it's inside the outer loop.

Other than that, I think you are close to a working solution -- maybe consider how will you want to handle leading/trailing and consecutive space characters.

mitrmkar 1,056 Posting Virtuoso

>> 'ofstream': No such file or directory":

The C++ header files are listed in this Reference.

mitrmkar 1,056 Posting Virtuoso

The code you've posted seems to be OK, so if the problem still persists, go ahead and post all of the code.

mitrmkar 1,056 Posting Virtuoso

"Selected" is initially an uninitialized pointer (read: it is garbage). Unless it gets assigned inside the loops, ValidMove() receives garbage.

I think that instead of assuming that everything works as you think it should, you should verify that this actually is the case here, so how about ...

void Board::Move(char Xin,char Xto, int Yin,int Yto)
{
    // Be safer, initialize to NULL
    Piece* Selected = NULL;
	
    for(int Row = 0;Row < 9;++Row)
    {
        for(int Col = 0;Col < 9;++Col)
        {
            if (Player1Pieces[Col]->Y == Yin && Player1Pieces[Col]->X == Xin)
            {
                Selected = Player1Pieces[Col];
            }
            else if (Player2Pieces[Col]->Y == Yin && Player2Pieces[Col]->X == Xin)
            {
                Selected = Player2Pieces[Col];
            }
        }
    }

    // Now make sure that there was an assignment ...
    if(Selected == NULL)
    {
        // Uh-oh -- do something ...
    }
  ...
}

This would be minor progress towards figuring out the reason(s) for the failure.

mitrmkar 1,056 Posting Virtuoso

>> .. my head is just spinning

If the libraries seem daunting, you might check out a basic MSDN CryptoAPI example Creating an MD5 Hash from File Content.

Suzie999 commented: ace +1
mitrmkar 1,056 Posting Virtuoso

In addition to what nezachem stated, it looks like you are also simply exploding the stack with your buffer declaration

char buffer [INT_MAX];
mitrmkar 1,056 Posting Virtuoso

>> output becomes full of INF INF INF 100 times :-)

You have to initialize the sum_* variables.

mitrmkar 1,056 Posting Virtuoso

It looks like it ought to work as such. However, you could check that;

  • You have the ON_WM_TIMER() macro in the dialog class' message map.
  • SetTimer() succeeds (returns a nonzero value).
  • UpdateData() succeeds (returns a nonzero value).
Jsplinter commented: Thank you so much! The bullet points made your answer even clearer! +1
mitrmkar 1,056 Posting Virtuoso

>> RNInterpreter.C:8: note: (perhaps a semicolon is missing after the definition of ‘Thousand’)

Your compiler is suggesting that Thousand.h looks like

class Thousand
{
  // All your Thousand stuff here ...

} // <--- ... but no ending semicolon after the curly bracket
mitrmkar 1,056 Posting Virtuoso

>> If you are compiling the program for UNICODE then why aren't you getting similar errors on all the other lines in your program (such as line 5)? fopen() is the non-UNICODE version, so the code is valid as such - although it is confusing. One option would be to completely stick with MFC i.e. using CStdioFile/CString for reading the file.

mitrmkar 1,056 Posting Virtuoso

Alright, then wrap the string literals with the _T() macro (from <tchar.h>), like so;

m_strLine.Replace(_T("\n"), _T("\r\n"));
mitrmkar 1,056 Posting Virtuoso

You want

m_strLine.Replace("\n", "\r\n");

>> m_strLine.Replace ( '\n' , '\r\n' );

That should give you a warning or two, are you ignoring compiler warnings?

mitrmkar 1,056 Posting Virtuoso

>> it also displays the two parent directories, '.' and '..'.

Line #30 stores both "." and ".." in addition to the directory and file names, so you have to work around that.

mitrmkar 1,056 Posting Virtuoso

If you have MS Word, then open the document in Word and do a Find/Replace, replace two adjacent spaces with a single space.

mitrmkar 1,056 Posting Virtuoso

>> Well, does'nt dereferencing unallocated memory lead to memory access violation

Not necessarily. Simply don't expect anything, that would indicate that something is seriously wrong, to happen.

>> Run-Time Check Failure #2 - Stack around the variable 'a' was corrupted
>> What exactly does the above error mean?

When you build a Debug configuration with /RTCs option on, the compiler inserts code that tries to detect stack corruption - this time you did an out-of-bounds write, which got detected.

See RTC (Run-Time Error Checks)

mitrmkar 1,056 Posting Virtuoso

Apparently you are accessing memory to which you have read-access. Generally, there are no built-in safety nets with regards to e.g. reading/writing out of array bounds and other things alike - you just have to be careful.

mitrmkar 1,056 Posting Virtuoso

In your first case, pDerived ends up being a NULL pointer. When you call TestD() through it, the this pointer will also be NULL (inside TestD() ) - hence the crash.

In the latter case, you are trashing memory worth of two ints approximately where your allocated Base object is stored - so, it certainly is not working by any means. Rather just bad luck that it is not crashing also.

mitrmkar 1,056 Posting Virtuoso

>> problem is getting the filename from the switch function back into the main

In order to do that, you need to pass in the address of the pointer (filename) that you will be setting inside this setup() function. C passes arguments by value, i.e. generally arguments passed to a function are copies of the original ones. It's a basic concept you need to wrap your head around.

Maybe you'll understand better if you run the below code.

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

static void setup(int, char **, char **);

int main(int argc, char ** argv)
{
    /* Simulate arguments to the program ... */
    char * local_argv[] = { "prog.exe", "-f", "foobar", "-c", "file.txt", NULL };

    /* Number of them, excluding the terminating NULL */
    int local_argc = sizeof(local_argv)/sizeof(*local_argv) - 1;

    char *filename = NULL;

    /* Pass in the address of the 'filename' pointer ... */
    setup(local_argc, local_argv, &filename);

    /* Did we get it? */
    if(filename)
        printf("filename [%s]\n", filename);

    return EXIT_SUCCESS;
}

static void setup(int argc, char **argv, char ** arg_filename)
{
    /* Only recognize c and f */
    const char *optstring = "c:f:";
    char option;

    while ((option = getopt(argc, argv, optstring)) != EOF)
    {
        switch (option)
        {
        case 'c':
            /* This modifies the 'filename' pointer inside main() */
            *arg_filename = optarg;
            break;
        default:
            printf("skipping [%c] [%s]\n", option, optarg);
            break;
        }
    }
}

P.S. You could use the Preview Post button to see that you've e.g. gotten the CODE tags right.

mitrmkar 1,056 Posting Virtuoso

See GetPrivateProfilexxxxxx()/WritePrivateProfilexxxxxx() functions in MSDN

mitrmkar 1,056 Posting Virtuoso

dynamic_cast<CTriangle*>(ppoly1) gives you a NULL pointer, through which the call gets made. If you were to modify the (non-existent) object's state inside the triFunc() , then you would get a run-time error, but because you just return the constant value (5), it appears to 'work'.

mitrmkar 1,056 Posting Virtuoso

>> The last output to the screen is the prompt to enter the name of the output file.

Once you've gotten out of the initial while() loop, I believe you use Ctrl+Z to stop entering coordinates, cin has eof bit set, which you must clear() before trying to get any other input (otherwise cin remains non-functional).

>> Then a MS alter window pops up with the message of an unhandled exception.

The exception gets thrown by the error() function because oname remains what it is initialized to (" "), look into std_lib_facilities.h for details. You might wrap the code in a try/catch block, i.e.

int main () try
{

  < all your code here >

}
catch(std::exception & e)
{
  // What does it say?
  cout << e.what() << endl;
}
mitrmkar 1,056 Posting Virtuoso

>> How do I check if a member of a struct is null?

Just like you are doing, i.e.

// Is it a NULL pointer?
if(ErrorInfo->TestName != NULL)
{
  // No it isn't ...
}

>> debug shows it as 0xccccccc, "")

This value 0xccccccc tells you that you are dealing with an automatic ErrorInfo variable, whose TestName member has NOT been initialized by you - it's an uninitialized variable. The value you see, is set by the Microsoft's debugging runtime library - a handy feature for spotting uninitialized variables.

So, what you need to do, is to initialize the variables. Either write a constructor which initializes the pointers to NULL, or if you are actually writing C instead of C++ ..

struct ErrorInfo errInfo;
errInfo.TestName = NULL;
// Initialize the rest of the members ..

P.S. An overview regarding various fill patterns and such Win32 Debug CRT Heap Internals.

mitrmkar 1,056 Posting Virtuoso

I think you'd rather want to use execvp() , see exec() - scroll down to Using execvp(), there's a minimum usage example.

mitrmkar 1,056 Posting Virtuoso

>> when I iterate through login_times, all of them have the same time value

asctime() uses a single static buffer and returns a pointer to this buffer every time you call it. In other words, all pointers that you store in the login_times array, point to the very same location in memory - hence the behaviour.

How about storing the time_t values inside the login() function and only use localtime()/asctime() when you need a string representation of the times? I.e.

/* Somewhere you'd have ... */
time_t login_times[NUMOFEMPLOYEES] = {0};

int login()
{
  ...    

  scanf("%d", &id);

  if ( (id < NUMOFEMPLOYEES) &&  (id >= 0) )
  {
    ...

    /* Store the time of login ... */
    login_times[login_counter] = time(NULL);
    ...

and use later ..

printf("login time: %s\n", asctime(localtime(&login_times[ <some valid index here> ])));