mitrmkar 1,056 Posting Virtuoso

I m not getting..it..

some more info or example code plz...

Since you appear to be on Windows, one way is to use GetFileAttributes(), see
http://msdn.microsoft.com/en-us/library/aa364944.aspx

mitrmkar 1,056 Posting Virtuoso

A note regarding clipboard usage, whenever you successfully open the clipboard, don't forget to close it by calling CloseClipboard() when you're done with the clipboard operations.

Nick Evan commented: yup +6
mitrmkar 1,056 Posting Virtuoso

Ok, one more question if you don't mind helping me out. I would like to make it so that if the line is less than 79 characters long, it will check the next line to see if the first word will fit on the current line without passing the 79 character limit.

Remember the length of the line stored in 'file'. Then, when you read in a line, lookup the first space in the input, so you get the length of the first word and if the length is small enough, replace the last newline with a space and append the word + newline to 'file'. Of course, you could make it work so that multiple words will be appended to the last line.

mitrmkar 1,056 Posting Virtuoso

The problem probably lies in how you use indexes. Note that array indexes are zero-based i.e. if you have an array holding 5 elements, the last valid index is 4, not 5. Consider

const char *article[ 5 ] = {"the", "a", "one", "some", "any" }; 
int i;
// print all 5 strings .. valid indexes are 0 .. 4
for(i = 0; i < 5; ++i)
{
    printf("%d=%s\n", i, article[ i ]);
}

With this regard you need to revise your code.

mitrmkar 1,056 Posting Virtuoso

A couple of things, get rid of the eof() in the while() loop, instead use

int format_file(string filename)
{
    ...
    while (getline(readfile, line))
    {
    ...
    }
}

If 'line' contains only whitespace, then the following will crash because line.length()-1 will be negative

//check for trailing spaces
 while (line.substr(line.length()-1) == " ")
       line.erase(line.length()-1);

You don't have to use substr() to check for individual characters, better way is

if(line[ valid_index_here ] == ' ')
...
mitrmkar 1,056 Posting Virtuoso

You might post the relevant parts of the code, otherwise there is no way to help much more.

mitrmkar 1,056 Posting Virtuoso

Sorry, I forgot to mention about the argv. Argv[0] is originally the program name, but after dealing with flags, the program does some magic (that I haven't really tried to figure out because it doesn't really affect the outcome) that ends up with argv[0] as the url.

The original program modified the argv strings. I'm trying to use another variable and failing.

How about getting rid of the original magic altogether? So you'd have untouched argv[] and simply hard-coded opt_httphost = "the hard-coded address"; .

mitrmkar 1,056 Posting Virtuoso

The memory that argv[0] points to is not writable.

I want to hard code the address in the program.

Why don't you just do something like

opt_httphost = "the hard-coded address";
mitrmkar 1,056 Posting Virtuoso

I guess you are after this

class test
{
    bool is_good;

public:
    test() : is_good(true){}

    operator void * ()
    {
        if(is_good)
            return (void*)this;
        else
            return 0;
    }

    void go_bad()
    {
        is_good = false;
    }
};

int main()
{
    test t;

    if(t)
        cout << "good\n";
    else
        cout << "bad\n";

    // change the state ...
    t.go_bad();

    if(t)
        cout << "good\n";
    else
        cout << "bad\n";

    return 0;
}
William Hemsworth commented: Great simple answer. Thanks :) +2
mitrmkar 1,056 Posting Virtuoso

Hi niek_e,

I have change the function to this but still I can't get the value.

int updateCorrectTotal(char posi, int poin, int tFoward, int tBack)
{
 if (posi == 'F')
    return tFoward += poin; 
 else {
    return tBack += poin;
}

It seems like you might intend to modify tForward and tBack in that function. In that case you have to pass those arguments by reference instead of by value, which is now happening.
To pass by reference declare the argument with a reference type, see below

int updateCorrectTotal(char posi, int poin, int [B]&[/B] tFoward, int [B]&[/B] tBack)
{
 if (posi == 'F')
    // the variable that tFoward references, will be incremented by poin
    return tFoward += poin; 
 else {
    // the variable that tBack references, will be incremented by poin
    return tBack += poin;
}
mitrmkar 1,056 Posting Virtuoso

You are rigth, ToArgb() does not return the value of the color.
Do you know how could I make it?

The Color has the respective R, G and B members which you can access directly.

mitrmkar 1,056 Posting Virtuoso

ToArgb() returns the combined Alpha/Red/Green/Blue value packed in 32 bits, so if you are expecting it to return values in range 0..255 then you have misunderstood that function.

mitrmkar 1,056 Posting Virtuoso

I'm guessing that i or j has an invalid value when calling GetPixel(i,j).

mitrmkar 1,056 Posting Virtuoso

it does not work properly

Could you be more specific about what it fails to do?

mitrmkar 1,056 Posting Virtuoso

have a compileerror that says:

'mysort' : illegal use of this type as an expression

You are missing the parenthesis there ... std::sort( Sorting.rbegin(), Sorting.rend(), mysort[B]()[/B]);

I have a few wonderings here at the same time. I beleive that the sortstruct has to get the substrings from the Sorting vector that are inside the buttoncontrol.
I am not sure how this communication will work.

The sort() algorithm calls the mysort's bool operator () ( ... ) to determine the sort order of the vector's strings. The communication is taken care by the sort() algorithm internally.

I am not sure what "a" and "b" represents in the struct code below.

They represent the individual strings whose relative order needs to be determined i.e. the strings that are stored in the vector being sorted. The sort() algorithm figures out which strings to pass in to the mysort's comparator (two at a time), the comparator just needs to tell the result (bool) of the comparison.

mitrmkar 1,056 Posting Virtuoso

'Form1::Form1::mysort' : a native type cannot be nested within a managed type 'Form1::Form1'

OK, now I understand what you meant in your previous post. The error means that you are not allowed to nest the (native c++) struct mysort inside the managed class.
To avoid that, simply define the struct mysort outside the Form1 class (and any other managed class for that matter), i.e.

#include "stdafx.h"
#include <string>
#include <algorithm>
using namespace std;

// the native C++ struct 
struct mysort
  {
  bool operator () ( const std::string& a, const std::string& b )
    {
    std::stringstream as( a );
    std::stringstream bs( b );
    double ad, bd;
    as >> ad;
    bs >> bd;
    return ad < bd;
    }
  };

// then the usual 'using ...' stuff ...
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
// etc ...

// and then the Form1 class ...
public ref class Form1 : public System::Windows::Forms::Form
{
// rest of the Form1 class's code follows ...
mitrmkar 1,056 Posting Virtuoso

Is this possible to use when you are writing the other code inside a
buttoncontrol (Managed Area) ?
I had some problem with this before also.

I think you should very well be capable of using code inside a button click handler i.e.

// inside a handler
 vector<string> v;
  v.push_back( "3.1,there" );
  v.push_back( "-0.7,hello" );
  v.push_back( "10.0,friend" );
  v.push_back( "3.2,my" );
  sort( v.begin(), v.end(), mysort() );

There is no need to change the struct mysort , i.e. have it like Duoas wrote it.

mitrmkar 1,056 Posting Virtuoso

Actually no, I get an error message saying:
"cannot convert from std::string to const char."

The parameters for strcat are: (char*, const char).

I assume variable2 is std::string, in which case you are to use:

strcat(variable1, variable2.c_str());

Just in case you are not too familiar with std::string, you can avoid strcat() completely, by simply:

std::string variable1 = "something" ;
std::string variable2 = " else";
// concatenate the strings
variable1 += variable2;
CodeBoy101 commented: Perfect!! +1
mitrmkar 1,056 Posting Virtuoso

See the comments for explanation for the error ...

void *audio::audioThread( void *ptr )
{
[B]     // ptr is NULL here[/B]
     audio *play = (audio *)ptr;

     // now you call playAudio() through a NULL pointer 
     play->playAudio();
     delete play;
     return NULL;
}

void audio::playAudio(void)
{
     // here the 'this' pointer is NULL, hence you have no access to
     // member variables, so the seg-fault is coming up ...
     test = 0;
     /* playback code */
}

int audio::play(char *filename)
{
     test = 1;

     // Here it starts to go wrong, because you pass in 
     // NULL as argument to audio::audioThread() ...
     if (pthread_create( &playThread, NULL, &audio::audioThread, NULL) != 0)
     {
             return -1;
      }

     return 0;
}
mitrmkar 1,056 Posting Virtuoso

Is there a way to convert from an integer to a string?

Yes, one way of doing it is ...

#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main()
{
	int x = 123;

	stringstream ss;
	string s;

	ss << x;
	ss >> s;

	cout << s;

	return 0;
}
CodeBoy101 commented: Perfect!!! +1
mitrmkar 1,056 Posting Virtuoso

One more method to remove all curves is ...

z1->GraphPane->CurveList->Clear();
mitrmkar 1,056 Posting Virtuoso

For the line below, the code also attach some text to the diagram "Curve1" so this text adds each time I press the button. So it seems that a line and the text just adds for each buttonpress.

LineItem ^myCurve;
myCurve = myPane->AddCurve( L"Curve1", list, Color::Red, SymbolType::None );

Yes, AddCurve() adds a new curve (and the related title to graph's legend) as its name implies.

What I had in mind but are not sure is that if there is any method to Clear() everyting in the diagramcontrol as you do for a textBox ex: textBox1->Text = "". The control is called zg1 but I cant find any ->Clear() members or ->Delete().

Related to that ...

// remove all curves
while(z1->GraphPane->CurveList->Count > 0)
    z1->GraphPane->CurveList->Remove(z1->GraphPane->CurveList[0]);
// ... now you need to add at least one curve to have something
// displayed
// remove a specific curve
CurveItem ^ remove = z1->GraphPane->CurveList["name_of_the_curve"];
if(remove)  // does it exist?
    z1->GraphPane->CurveList->Remove(remove);
// instead of removing/clearing curves,
// a light-weight method is to modify the curve's list directly
CurveItem ^ curve = z1->GraphPane->CurveList["name_of_the_curve"];
if(curve)
{
    // try accessing the list
    IPointListEdit ^list = dynamic_cast<IPointListEdit ^>(curve->Points);

    if(list)
    {
        // throw away all current values
        list->Clear();

        // ... and add some new
        for ( int i = 0; i < 36; i++ )
        {
            double x = (double)i * 5.0;
            double y = Math::Sin( (double)i * Math::PI / 15.0 ) * 16.0;
            double y2 = y * 13.5;

            list->Add( x, y );
        }

        // depending …
mitrmkar 1,056 Posting Virtuoso

You might use seekg() along with tellg(), see here for an example
http://www.cplusplus.com/reference/iostream/istream/tellg.html

mitrmkar 1,056 Posting Virtuoso

Move the two lines to a .cpp file, now they seem to be in a header file.

I.e. these two lines ...

nodePtr head=NULL;
nodePtr current=head;
mitrmkar 1,056 Posting Virtuoso

but with this i am getting linker errors

There are quite many linker errors, which errors are you receiving?

mitrmkar 1,056 Posting Virtuoso

You simply need to initialize the pointers ...

nodePtr head = 0;
nodePtr current = 0;

The extern declarations of the pointers you have there, do not impact the actual variables' values in any way, in case you were expecting that to happen.

mitrmkar 1,056 Posting Virtuoso

Maybe I am just being dumb in this situation, but wouldn't there then need to be spaces like so:

109884 , 109278 , 1078508

No need for spaces, although there can be tabs/spaces, but those will be ignored. It will work as long as there is a separating comma (or any other character that cannot be taken as part of value, for that matter).

mitrmkar 1,056 Posting Virtuoso

The following might work for you, assuming that the values are always comma-separated

string line;
	double x,y,z;
	char dummy; // for skipping commas

	while ( getline(canopyfile, line) )
	{
		stringstream iss(line);

		if(iss >> x >> dummy >> y >> dummy >> z)
		{
			holder.setx(x);
			holder.sety(y);
			holder.setz(z);

			canopyvec.push_back(holder);
		}
		else
		{
			// failed to extract 3 values
		}
	}
cbattagler commented: Thank you again +1
mitrmkar 1,056 Posting Virtuoso

If you have the BGI documentation, then go through it, and learn how the functions you are using (all of them) indicate an error condition of any kind. If you don't have it, then you might want to take look in
http://www.cs.colorado.edu/~main/cs1300/doc/bgi/ to have an idea of how the BGI works.

Then add code that checks for any error(s) that might have occurred. This way you may find out the root cause.

mitrmkar 1,056 Posting Virtuoso

I can't do that. I have to define it in the header file or else I get this error:

You need to #include the respective header file in interpotcntrlparams.cpp.

mitrmkar 1,056 Posting Virtuoso

Move the definition of QStringList FuncCntrlParams::type_pairPotList into the respective .cpp file.

mitrmkar 1,056 Posting Virtuoso

1) To make the call Date::set_default(), needs the set_default() to be a static member function.
2) It is not enough to declare a static member variable inside the class declaration, you also need to define and optionally initialize it.

class Date
{
    // a non-const default date
    static Date default_date;

    // a const default date
    static const Date default_date_const;

    int d,m,y;        

public:
    static void set_default(int dd,int mm,int yy);
    Date(int,int,int);
	
    <snip>
}; // class Date ends here

// the non-const default date defined & initialized here
Date Date::default_date(9,7,2000);
// the const default date defined & initialized here
const Date Date::default_date_const(9,7,2000);

int main()
{
    // Date::set_default() is now a static member function,
    //  so the following call works
    Date::set_default(9,7,2000);
    Date S(3,7,1991);
    cout<<"Date"<<S.show_date()<<"-"<<S.show_month()<<"-"<<S.show_year()<<"\n";
    S.addyear(18);
    cout<<"Date"<<S.show_date()<<"-"<<S.show_month()<<"-"<<S.show_year();
    return 0;
}
Nick Evan commented: thanks for the correction +5
mitrmkar 1,056 Posting Virtuoso

Well, the above didnt work. To look at that output see attachment.

Sorry, but I'll have to give up on that one then.

And anyway latest Borland C++ compilers dont support BGI graphics.

About upgrading your compiler, the main point is that you should give up on an antique compiler in case you are into modern computing.

The program could be written only in Turbo C++ 3.0.

I actually tried that one on Dev-C++ with Winbgi library and it worked for me :).

mitrmkar 1,056 Posting Virtuoso

If your intention is to convert a string of digits to a long value, then see the strtol() function
http://www.cplusplus.com/reference/clibrary/cstdlib/strtol.html

mitrmkar 1,056 Posting Virtuoso

Nope, it doesnt work, instead some of the text's pixels are coming in the borders of the rectangle, i.e it looks corrupted on its sides only.

Hmm, sorry but I don't fully understand that one. Perhaps you could try the following ...

void boxout(int xstart,int xend,int ystart,int yend,char item[])
{
  moveto(xstart,ystart);
  
  setcolor(LIGHTGRAY);  
  setfillstyle(SOLID_FILL,LIGHTGRAY);
  rectangle(xstart,ystart,xend,yend);
  floodfill(xstart+1,ystart+1,LIGHTGRAY);

  // at this point you should have a filled LIGHTGRAY rect

  for(int i=xstart;i<=xend;i++)
   {
    putpixel(i,ystart,WHITE);
    putpixel(i,yend,DARKGRAY);
   }

  for(int i=ystart;i<=yend;i++)
   {
    putpixel(xstart,i,WHITE);
    putpixel(xend,i,DARKGRAY);
   }

  // lastly, output the text
  setbkcolor(LIGHTGRAY);
  setcolor(BLACK);
  outtext(item); 
}

Then lastly, I think you really should consider getting yourself a newer development system, like MS VC 200x Express / Borland C++ Builder, which are available for free.

mitrmkar 1,056 Posting Virtuoso

This is simple to fix ... relax

Employee employee1(); // <- actually declares a function returning an Employee
// instead use ...
Employee employee1;

If the Employee's constructor would take argument(s), then you could have it like

string FirstName, LastName;
Employee employee1(FirstName, LastName);

Regarding code tags, the ending tag is [/code].

mitrmkar 1,056 Posting Virtuoso

Try relocating the outtext(item) call ...

void boxout(int xstart,int xend,int ystart,int yend,char item[])
 {
  setcolor(BLACK);
  moveto(xstart,ystart);

  setcolor(LIGHTGRAY);
  setfillstyle(SOLID_FILL,LIGHTGRAY);
  rectangle(xstart,ystart,xend,yend);
  floodfill(xstart+1,ystart+1,LIGHTGRAY);

  for(int i=xstart;i<=xend;i++)
   {
    putpixel(i,ystart,WHITE);
    putpixel(i,yend,DARKGRAY);
   }

  for(i=ystart;i<=yend;i++)
   {
    putpixel(xstart,i,WHITE);
    putpixel(xend,i,DARKGRAY);
   }

  outtext(item);
  }
mitrmkar 1,056 Posting Virtuoso

You must take care to use operator 'delete' only on objects that have been allocated using operator 'new', without any exceptions.

If you look into your code, you will see that this is NOT happening.
In the checkOutVideo() function you have; RentedVideo newRentedVideo(avblVideo->getVideoTitle() ...); i.e. the newRentedVideo object has not been allocated using new, instead it lives on stack only, and in the RentedVideo() constructor you assign the class' static pointer to this stack object. And later on, via checkInVideo() you eventually use the delete operator on that address, that is where the damage (silently in this case) occurs.

So you need to check all the code that it behaves well with regard to new/delete.

Maybe your allocation and deallocation of Customer and AvailableVideo classes is OK, I'm assuming here that you allocate those objects using new, since you load the data from file.

mitrmkar 1,056 Posting Virtuoso

The end condition for the loop where you iterate over the list might be wrong or your list is not terminated properly (or something else).

If you've been wondering about this for a week now, it is probably better to post code that is relevant to the problem.

mitrmkar 1,056 Posting Virtuoso

If you want to stick with the original ostream& operator<<(ostream& out, const Card& c) then you need to make the getSuit() method also const ..

const char getSuit() const;
// and ...
const char Card::getSuit() const

One more link for you ..
http://en.wikipedia.org/wiki/Const_correctness#Methods

mitrmkar 1,056 Posting Virtuoso

That happens because you have [B]System::DateTime[/B] LastSourceTime = CurrentSourceTime; <=> LastSourceTime is there a variable local to the if -block. You have to change it to simply: LastSourceTime = CurrentSourceTime;

mitrmkar 1,056 Posting Virtuoso

I mean can we get the pipe to enter into the string or a char array?.

char str[20];
sky.exe > str;

Basically you need to devise a char array or a string, which contains the command to execute (though depends on what you will use to execute the program i.e. CreateProcess(), ShellExecute() etc, i.e. you may need the command split into several strings)

But anyway, consider an example where the whole command line is in a single string

string sky = "c:\\sky.exe";
string file_out = "c:\\temp\\sky.txt";
string cmd = sky + " > " + file_out;
system(cmd.c_str());
mitrmkar 1,056 Posting Virtuoso

Should sky.exe >out.txt be written in a specific place? or anywhere else?

Specify any location of your choice that you have write access to.

Regarding the system() and std::string, you can use: system(some_string.c_str());

Nick Evan commented: You're right. I forgot about c_str() +5
mitrmkar 1,056 Posting Virtuoso

You exceed the array bounds by using the pre-increment operator in Temperatures[++Count] = CurrentTemp; change it to Temperatures[Count ++] = CurrentTemp;

mitrmkar 1,056 Posting Virtuoso

<< if I try to push changed data using function, I get just the same word n times:
That happens because you are pushing pointers to one single buffer you have in your whole program, and that buffer is char recordd[].
In other words, you can write to that buffer as many times as you wish, but the data that was last written to it, is the only data you ever can get out of it.

So, you need to allocate dynamic memory into which you copy the AD()'s output, that you eventually push onto the stack. Maybe you get the idea from the following ...

int main()
{
    POINTER start = NULL;
    char *DELIMITERS = " ";  
    char *str,record[100],*o;
    [B]int len;[/B] // holds the length of string that will be pushed
    char line[]="jjj   yyyy dfsfsd sdfsdf sdfsdfsdf sdfsdfsfd sdfasdfafs Intelect";
	
    str = strtok(line, DELIMITERS);
    // Consider recordd as just an intermediate work buffer 
    // for the AD() function
    char recordd[sizeof(record)] = {0};

    while (str)
    {
        // Pass the input to AD()
        AD(str, recordd);
        // Get the length of string and account for a terminating null char
        len = 1 + strlen(recordd);
        if(len > 1) // did AD() give some output?
        {
             // Allocate the memory needed to hold the string to push
             char * temp = (char *)malloc(len * sizeof(char));
             if(temp)
             {
                 // malloc() succeeded, now copy the data from recordd 
                 strcpy(temp, recordd);
                 // and push it
                 push(&start, temp);
             }
        }
        str = strtok(NULL, DELIMITERS); …
mitrmkar 1,056 Posting Virtuoso

Below is one option, maybe that is what you are after

private: System::Void button5_Click(System::Object^  sender, System::EventArgs^  e) 
{
    Form2 ^form2 = gcnew Form2;
    form2->Show();
}
mitrmkar 1,056 Posting Virtuoso

I think the original findHighest() code was working quite well, to get the
actual highest score, simply use person[max].testScore once the index of the
highest score is known (i.e. max in this case), so ...

int findHighest(studentType person[])
{
	// assume highest score is at index 0
	int max = 0;

	for (int r = 1; r < numStudents; r++)
	{
		if (person[max].testScore < person[r].testScore)
		{
			max = r;
			// currently highest scored at index max now
		}
	}

	// Tell what we got: the index and the actual score
	cout << "highest score is at index: " 
		<< max 
		<< " and the score is: " 
		<< person[max].testScore;

	// return the index which can be used to subscript the person array
	return max; 
}
mitrmkar 1,056 Posting Virtuoso

If you need to copy a file, you can use System::IO::File::Copy()

mitrmkar 1,056 Posting Virtuoso

So for instance, if I have vector<int> vecList; as my vector and I want to replace vecList[5] with an integer entered by a user, how exactly can I do that?

Simply by vecList[5] = int_from_user; To lookup a value to change, you can use std::find()

#include <algorithm>
...
vector<int> v;
...
const int value = 234;
vector<int>::iterator srch = find(v.begin(), v.end(), value);

if(srch != v.end())
{
    // increment the value by one
    *srch = value + 1;
}
mitrmkar 1,056 Posting Virtuoso

You are missing using namespace System::Collections::Generic;