mitrmkar 1,056 Posting Virtuoso

I missed the brackets for the check array in the if statement.

There is more than just the brackets here, i.e.

// not "\n", but instead ...
if ( check[0] != '\n' )
Grn Xtrm commented: brackets among other things... :) Thanks +2
mitrmkar 1,056 Posting Virtuoso

As far as 'INCORRECT' msgbox is concerned, I think what I wrote made you conclude that msgbox doesn't appear. Sorry for that.
...
I never said, my code is not working, just not achieving the desired result.

OK, now I understand what you were after. English being far from my native language sometimes makes even simple things hard to really understand (and it's annoying).

mitrmkar 1,056 Posting Virtuoso

Ok do you mean the binary is 32 bit or 64 bit? I am running 32 bit version of my exe on x86 and x64 processor.

OK, since it is a 32 bit binary, try GetNativeSystemInfo(), read the full documentation on GetNativeSystemInfo()/GetSystemInfo().
If you won't be needing a 32 bit binary, then compile it into 64 bit and use GetSystemInfo().

mitrmkar 1,056 Posting Virtuoso

Since you are not seeing MessageBox("INCORRECT"); it's apparent that if(s == correct) always evaluates to true (assuming that CI2T::IsCorrect() gets called). Have you tried debugging? Put breakpoints at proper places, so that you'll be able to trace how s is getting its value (and correct too, unless it's a constant).

Also, the game time is being maintained, is it possible that I can kill timer during the game, e.g. I have started the game and somebody interrupts me for say 30 sec, once I come back to game, the question has passed.

If I understood the question right, it is possible. You don't necessarily need to kill the timer, instead maybe have a state variable telling whether or not the game is paused. If paused, then simply don't do anything when the timer fires. But you can do it either way.

Note, I'm assuming that the game is coded 100% by you. If it is not, then you have to dig into the source code to be sure that your changes (e.g. pause/resume) won't break anything.

Can I use some keystroke to pause the game at that state and resume it again with the same keystroke when I am ready to play it again.

Most probably yes.

I think it's difficult to get an idea here.

Well, without seeing the source code, questions like these are quite vague (considering a MFC program). There are a zillion things that could be wrong, maybe more ;)

PS. …

mitrmkar 1,056 Posting Virtuoso

You haven't told whether your program is 32 or 64-bit.
Anyway, did you try GetNativeSystemInfo() ?

mitrmkar 1,056 Posting Virtuoso

Just a suggestion, how about first primarily focusing on coding well-working basic routines (i.e. sorting, searching in this case), without them being 'slightly modified' for any specific purpose. Hence you would have something solid to further build upon.

In other words, you would have a sorted array of strings, and you'd be able to issue a simple search telling you if a string is in the array, and if so, where it is. Hence the next problem to solve would be to try to figure out how many occurrences of the string there are. (It seems like your attempt to be efficient here is what leads to the confusion.)

mitrmkar 1,056 Posting Virtuoso

:icon_eek: There are no checks against failed memory allocations.

mitrmkar 1,056 Posting Virtuoso

i cant figure out wherez the error or at which line exactly, can u guyz specify which line/s?

Sigh, surely you must understand by now, that it's practically impossible to believe that You wrote that code yourself, right?.

Anyway, perhaps read this

mitrmkar 1,056 Posting Virtuoso

what's missed in my "for" loop, this is how i write it:
for (int i = 1; i <= 10; i++)

can u specify?

You are looking at the wrong line there. You have several for loops, of which some are correct and some are not. The link that Salem posted explains the error quite well.

mitrmkar 1,056 Posting Virtuoso

tell me where exactly i should declare the identifier "i"

If you look at the compiler error message, it includes the file and also the line number where the error occurs, for example, given an error message like:

foobar.cpp(10) : error C2065: 'i' : undeclared identifier

you should open foobar.cpp and look at the line 10. Furthermore, since you seem to be using Visual Studio, you can double-click on the error message (shown in the Output window) and the IDE will navigate to the correct file/line.

mitrmkar 1,056 Posting Virtuoso

NOTE:

ب
=
0x0628
= 
"\u0628"

0x0628 is not UTF-8, but rather UTF-16. Dave Sinkula's 0xD8 0xA8 is the UTF-8 representation of \u0628.

mitrmkar 1,056 Posting Virtuoso


I'm trying to use taglib in my Qt-program but it won't work. With this code, it doesn't compile

<snip>

What's wrong?

Difficult to say, maybe even your compiler is faulty. In this kind of cases, rather post the actual compiler error message(s) along with the offending piece of code.

But what I find odd is that the error says it can't find a constructor with a char const* but isn't it supposed to be const char*?

Those are equivalent, hence you cannot compile e.g. the following

class nocando
{
    nocando(const char * p) 
    {}
    nocando(char const * p) 
    {}
};

By the way, which compiler/version are you using?

mitrmkar 1,056 Posting Virtuoso

So does anyone know how to make use of getline() for this?

You were on the right track (i.e. getline()) in the beginning, so you might get the input doing e.g. the following:

#include <iostream>
#include <string>

using std::string;
using std::getline;
using std::cin;
using std::cout;

int main()
{
    string input;
	
    // Let the user type in the whole line ...
    getline(cin, input);
	
    // What did we get?
    cout << "[" << input << "]";
	
    // Todo: iterate over the input extracting the individual 
    // words, using e.g. a stringstream

    return 0;
}
mitrmkar 1,056 Posting Virtuoso

Thanks Dave, I tried -pedantic option and it is still only giving a warning to me. Shouldn't it be a nice and proper error?

Maybe try -pedantic-errors

mitrmkar 1,056 Posting Virtuoso

these are the warnings im getting but i was thinking they don't make much difference

With more GCC's switches turned on, you would have seen more warnings and actual errors. So, in addition to learning C, also get familiar with GCC, so that you can configure it to produce useful diagnostics. And in general, warnings shouldn't be ignored but fixed instead.

mitrmkar 1,056 Posting Virtuoso

thank you very much your reply and for your solution i was trying to do it completely differently
here is the code

// read the file from comand line and displys it
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

main(int argc, char *argv[])
{
  int fd ,numseats, i=0, ans, bufs=50;
  FILE* lp;
  char  ile[bufs];
  fd = open(argv[1],O_RDWR);
  
  if(fd <0)
    {
      printf("file s% not found",argv[1]);
      exit(1);
    }
  printf("would you like the output be send to file??1/2  :");
  
 
  if(scanf("%d",&ans) == 1)
    {
      printf("please specifie the file\n");
      scanf("%s",ile);
      lp=fopen(ile, O_RDWR); 
  
      while(read(fd, &numseats, sizeof(int)) > 0)
	fprintf(lp,"flight%4d: %4d seats available\n", i++, numseats);
    }
  else
    {

  while(read(fd, &numseats, sizeof(int)) > 0)
    printf("flight%4d: %4d seats available\n", i++, numseats);
    }
  /* finished */
  exit(0);
}

this code does compile but it gives me segmentation fault

Doesn't your compiler produce any warnings? Which compiler are you using?

mitrmkar 1,056 Posting Virtuoso

hey thanks a lot!I managed to write a few programs using code::blocks but I still didnt get how to do it without using an IDE.:(

The simplest example to compile C++ code would be:

g++ helloworld.cpp -o helloworld.exe

Since you are taking the very first steps, perhaps you'd be better off sticking with the IDE, letting it handle the compiler/linker options and such. There are quite a few of them, see the GCC documentation (link above).

mitrmkar 1,056 Posting Virtuoso

You need to tell the compiler what to do by specifying files/options on the command line. Clicking on the compiler executable will not do much as you've already noticed.

Perhaps read a basic tutorial, I'd suggest you to go through sections;
0.4 Introduction to development
0.5 Installing an Integrated Development Environment (IDE)
0.6 Compiling your first program

Oh, and the documentation for GCC can be found here

mitrmkar 1,056 Posting Virtuoso

That's my bad. I guess I had never seen it done that way. Apologies to the OP.

With e.g. GCC's -pedantic/-pedantic-errors options switched on, the code won't compile. So no reason for apologies :).

mitrmkar 1,056 Posting Virtuoso

I cant find the same with System^String in WinForms...

See e.g. String::IndexOf Method (String)

mitrmkar 1,056 Posting Virtuoso

I'm suspecting that you are unnecessarily trying to convert data back and forth (being somewhat unfamiliar with c++). So, if you'd describe in detail what you need to do, someone here might suggest a simple solution.

mitrmkar 1,056 Posting Virtuoso

I would like to put the string day[7]; as private since the days of the week will never change

Given the above code, you might have the string day[7] as a private member variable. So you must be doing something illegal in the code that you did not post.

Furthermore, why not make that a private static const member variable, so you'd have

class dayOfTheWeek
{
public:
    // <snip>
private:
    static const std::string days[7];
};

// and outside the class declaration ...
const std::string dayOfTheWeek::days[7] = 
{
    "Sunday",
    "Monday",
    "Tuesday",
    "Wednesday",
    "Thursday",
    "Friday",
    "Saturday"
};

If you don't make it a static member variable, then every instance of the dayOfTheWeek class has an unnecessary copy of that data (wasting memory).

Ancient Dragon commented: Good post +25
mitrmkar 1,056 Posting Virtuoso

Here's a start:

#include <iostream>

int main () {
     std::cout <<  "welcome to my program";
     return 0;
}

Sorry niek_e, but that's not actually useful since the OP is to write a C program (according to the instructions given)
;)

Nick Evan commented: touche! +12
mitrmkar 1,056 Posting Virtuoso

That sounds like something rather complicated. One thing I can say though is that if you are using WM_SETFOCUS/SetFocus() within that dialog box, then just don't. Those are not meant to be used with dialog boxes.
Rather use CDialog::GotoDlgCtrl() or WM_NEXTDLGCTL to set the focus.

mitrmkar 1,056 Posting Virtuoso

how can I solve the problem

Start off by reading the many answers you've already gotten so many times. If you don't understand a specific piece of advice, then ask for more details about that specific case. (I assume using English is not the problem for you here (?)).

And please pay close attention to what jonsca said above:
you need to be proactive in changing your program
If you don't, sorry to say but, in my opinion, you might as well stop posting problems related to that program.

PS. Learn how to use code tags when you post code. It is actually quite easy.

mitrmkar 1,056 Posting Virtuoso

But the codes works properly when G=280 and l=3...

Since you are unwilling to post any code, I guess that you have this

const int G=290;
const int L=3;
float ReplicatedMat[G+1][L];

inside a recursive function eventually causing the stack overflow.

[EDIT]
Perhaps run the program in the debugger and at the point of the stack overflow, view the Call Stack. That might tell you something useful.

mitrmkar 1,056 Posting Virtuoso

... so I don't have CPropertySheet::OnInitDialog()..

You could very easily arrange so that you'd have a class derived from CPropertySheet, in which case the above code snippet would do the job. I think that would be the 'most natural' way of doing what you are trying to accomplish.

I only have CPropertyPage::OnInitDialog()..

In that case you might try the following

// WM_INITDIALOG handler for your CPropSettingCriteria 
// property page class
BOOL CPropSettingCriteria::OnInitDialog() 
{
    BOOL bResult = CPropertyPage::OnInitDialog();

    // Try to get a pointer to the propertysheet
    CWnd * pParent = GetParent();

    if(pParent && IsWindow(pParent->m_hWnd))
    {
        pParent->GetDlgItem(IDCANCEL)->ShowWindow(FALSE);
        pParent->GetDlgItem(IDOK)->EnableWindow(FALSE);
    }

    return bResult;
}
mitrmkar 1,056 Posting Virtuoso

Have you tried the following ?

// WM_INITDIALOG handler of your property sheet class
// (derived from CPropertySheet)
BOOL CMyPropertySheet::OnInitDialog() 
{
    BOOL bResult = CPropertySheet::OnInitDialog();

    // Hide the Cancel button
    GetDlgItem(IDCANCEL)->ShowWindow(FALSE);

    // Disable the OK button
    GetDlgItem(IDOK)->EnableWindow(FALSE);

    return bResult;
}
mitrmkar 1,056 Posting Virtuoso

Dev is quite a good compiler and editor but IMO the debugger...sucks.

In that case you might want to try out VC++ 2008 Express.

mitrmkar 1,056 Posting Virtuoso

However it still seems to have an issue if i want to do the below.

CONST INT iCommPortCount = 5;
HANDLE comports[iCommPortCount];
comports[0] = CreateFile("\\\\.\\COM6", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,NULL);
comports[1] = CreateFile("\\\\.\\COM7", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,NULL);
comports[2] = CreateFile("\\\\.\\COM8", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,NULL);
comports[3] = CreateFile("\\\\.\\COM9", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,NULL);
comports[4] = CreateFile("\\\\.\\COM10", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,NULL);

This gives me the below on the first value of 'comports'

"error C2466: cannot allocate an array of constant size 0"

Are you doing that in the global scope, i.e. outside of any function? If you are, then move (at least) those CreateFile() calls inside a function.

mitrmkar 1,056 Posting Virtuoso

the ANSI file still came out Chinese, but the Unicode came out in English!

Now there is some kind of mismatch here, maybe you could zip the project (*.c*, *.h, *.rc) and post it here.

what should I do to make it keep coming out in English, maybe I should start saving my files as Unicode?

Probably it would be easier to stick with the ANSI and master the UNICODE later. First of all you have to understand their difference though and how that impacts your programming (that is actually one thing that you have just stumbled upon).

mitrmkar 1,056 Posting Virtuoso

OK,mitrmkar, the code compiled successfully but it still doesn't give me English

I suggest that
- open Notepad
- type some text and save a file as ANSI
- save it also as UNICODE

Open both the files with your app, and tell us what happens ...

FYI, for me your LoadTextFileToEdit() loads and displays ANSI text as it should.

mitrmkar 1,056 Posting Virtuoso

Sorry but I managed to leave out one thing regarding the above change.

// Since the function became an 'ANSI-version',
// use LPSTR instead of LPWSTR		
LPSTR pszFileText;
// and ...
pszFileText = (LPSTR)GlobalAlloc(GPTR, dwFileSize + 1);
mitrmkar 1,056 Posting Virtuoso

OK, the code compiled and my tmCharSet ids ANSI_CHARSET.
What do I do next ,please.Thank you for your time,frederick, and I'm sorry for my mistakes.

Since you are obviously compiling with UNICODE #defined, call the ANSI-version of SetWindowText excplicitly when setting the EDIT control's text (naturally do that only when you work with ANSI text).
As of now, your app displays a UNICODE text file (almost) as expected (try saving a file as UNICODE with e.g. Notepad and load that file).

As a general rule, read the documentation about the Windows functions/other stuff really _carefully_, it will pay off sooner than later.

So the fix is the following

pszFileText[dwFileSize] = 0; // Add null terminator
if(SetWindowText[B]A[/B](hEdit, pszFileText))
bSuccess = TRUE; // It worked!

PS. There are more things to fix in the code but I will not go into them now.

mitrmkar 1,056 Posting Virtuoso

Like I said -- the return value of the command interpreter is also pretty much useless. The command interpreter does not return the exit status (or exit value) of the program/process that was executed. If your program doesn't need that, then no harm done. Otherwise don't get the false impression that system() returns something that it does not.

I refuse to agree with that. Say you have the following two programs ..

// 42.cpp
// this one produces a program named 42.exe

int main(int argc, char* argv[])
{
	// simply return 42
	return 42;
}
// test.cpp
// this one produces a program named test.exe

#include <iostream>

int main(int argc, char* argv[])
{
	int result = system("42.exe");
	std::cout << "-> " << result << std::endl;

	return 0;
}

Assuming 42.exe is in the same directory as test.exe, the output of test.exe is:
-> 42

mitrmkar 1,056 Posting Virtuoso

The return code from system() is pretty much useless -- all it indicates is whether system() successfully ran the command or not. It says nothing about the program that system() ran.

That's not quite so. Basically system() returns the value from the command interpreter i.e. it can well be used like the OP is planning to use it. MSDN documentation about system()

mitrmkar 1,056 Posting Virtuoso

I beg to differ, in my copy of the ansi C spec section 2.2.4.2 - Numerical limits:

<snip>

am I reading it backwards and it means something else?

I think you are not understanding the following

Sizes of integral types

The values given below shall be replaced by constant expressions suitable for use in #if preprocessing directives. Their implementation-defined values shall be equal or greater in magnitude (absolute value) to those shown, with the same sign.

mitrmkar 1,056 Posting Virtuoso

If you need to resolve the path and file name of a .lnk file (i.e. a shortcut) that's dropped on the Audacity project, you'll need to use the IShellLink interface. Read about Shell Links in MSDN.

This is (fairly) new behaviour to Windows (might be in Vista) and I have searched for an example which I could understand with no luck!

Sorry but I don't quite understand what you are saying here, shell links have been around since Windows 95 / NT 4.0. I suppose Windows 7 hasn't brought anything new to shell links.

mitrmkar 1,056 Posting Virtuoso

Refresh.

I doubt that anyone here will take up the task of modifying the program.

A slight chance of getting some sort of assistance might be to contact the author, his contact information is available on the program's Help/About window.

mitrmkar 1,056 Posting Virtuoso
mitrmkar 1,056 Posting Virtuoso

There is an initialization failure ...

for( i = 0; i < n; i++ ) numberlist[i] == rand() % n ;
mitrmkar 1,056 Posting Virtuoso

I think the two friend declarations need template <class T>

template <class T>
class Tree
{
...
template <class T> friend void buildExprTree(Tree<T> & expr);
template <class T> friend int eval(Tree<T> & expr);
...
};
mitrmkar 1,056 Posting Virtuoso

There seem to be random *'s all over the code...

Yes, those *'s have been there for quite some time ...;)

mitrmkar 1,056 Posting Virtuoso

For example, this does not compile:

class Point
{
	private:
		//friend class PointFriend;
		double x,y,z;

	public:
		Point(const double xin, const double yin, const double zin) : x(xin), y(yin), z(zin) {}
};

class PointFriend
{
	private:
		friend class Point;
	public:
		PointFriend()
		{
			Point P(1.2, 2.3, 3.4);
			cout << P.x << endl;
		}
};

But if you uncomment the "friend class PointFriend;" and comment "friend class Point", it works correctly.

PointFriend must be a friend of Point because PointFriend's constructor accesses a private member of Point (i.e. P.x).

Whether or not "friend class Point;" is declared in the above example makes no difference because class Point does not make any use of class PointFriend. If it would, then you'd have to split the code into .h and .cpp files with appropriate #includes in order to have a mutual friendship.

P.S. Note that you can also have individual member functions as friends of a class.

mitrmkar 1,056 Posting Virtuoso

Looking at your previous post, there's an orphan if there ...

break;
            case '#':
                if 
            break;
            default:
mitrmkar 1,056 Posting Virtuoso

Or maybe I'm missing something now in the switch statements that can still allow me to use them...

Yes, you are missing semicolons ...

void bird :: double travel_time (double distance, terrain_type t)
{
     switch (t)
      {
            case PLAIN: travel_time = ((distance/landspeed)*1) ;
                        break;
            case HILL:  travel_time = ((distance/landspeed)*2) ;
                       break;
            case MOUNTAIN: travel_time = ((distance/landspeed)*3) ;
            // maybe add the final break too
                       break;
     }
}

The if-blocks won't work because you are trying to declare variables of terrain_type and compare them at once, i.e. use

double bat :: travel_time (double distance, terrain_type t)
{
       if (t == PLAIN)
       {
         distance = (distance/airspeed);
       }
       // and so on ...
mitrmkar 1,056 Posting Virtuoso

Do you mean the following?
-> Assign using strcopy();
-> Use a loop afterwards to cleanup ALL the memory ...

// in this case, there are 20 bytes available for use at ptr[0 .. 4], 
// one use might be by means of strcpy()
strcpy(ptr[0], "Hello ");
strcpy(ptr[1], "wond");

// cleanup ...
for(int i = 0; i < 5; i++)
    delete [] ptr[i];

// and finally
delete [] ptr;
mitrmkar 1,056 Posting Virtuoso

"cannot convert from const Node *const to Node* Conversion loses qualifiers". I'm not sure how to fix this.

You can use const_cast, i.e.

Node * temp = const_cast<Node*>(this);

Maybe you could revise the 'constness' of the code (I did not look too closely). Perhaps read about Const correctness.

mitrmkar 1,056 Posting Virtuoso

That is not quite correct, see comments

int main(void)
{
    /* Declare the '2D Array' */
    char ** ptr = new char * [5];
    ptr[0] = new char[20];
    ptr[1] = new char[20];
    ptr[2] = new char[20];
    ptr[3] = new char[20];
    ptr[4] = new char[20];

    /* Put some data in the array */
// below you lose all the above allocated 20 byte chunks because you 
// re-assign the pointers to strings, meaning that you cannot anymore 
// delete the allocated memory, which you should do
    ptr[0] = "Hello ";
    ptr[1] = "wond";
    ptr[2] = "er";
    ptr[3] = "ful";
    ptr[4] = " world !!!";

// instead you should e.g.: strcpy(ptr[0], "Hello ") and so on ..

    /* Print the array on the screen */
    for(int i = 0; i < 5; i++)
        cout << ptr[i];

    cout << endl;

// you are not deleting the 20 byte chunks here

    /* Cleanup */
    delete[] ptr;

    /* Wait for the user to press ENTER */
    cin.get();

    /* Tell the Operating System that everything went well */
    return 0;
}
tux4life commented: Thank you very much for correcting me ! +1
mitrmkar 1,056 Posting Virtuoso

I'm still wandering about the code that suppose to go in movePuzzle

void movePuzzle(int puzzle[][COLS], char dir, int rowcol)

it takes 3 arguments right? the array puzzle, the char 'v' or 'h', and the third argument is the number of index correspond to the vertical/horizontal.

Yes. A suggestion, maybe first exercise with a smaller problem, e.g. try to simulate the "(0 <= n <= 1) to move row n right 1 position".
You might have ...

const int COLS = 3;
int array[COLS] = {1,2,3};

// todo: shift the ints in the array right 1 position, after which 
// the array will be {3,1,2}