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

Line 3: that is not the way to pass an array. Omit the []. All you do is pass the name of the array, like this: mergesortinplace(0, (length/2), array);

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

win32 api function SetFileAttributes()

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

Making the file "read only" will NOT prevent an external application or the user from changing or deleting it. It mearly makes it more inconvenient. External applications or the user can always change the file permissions to read/write and either change the file's contents or delte it.

If you want to make it read-only only while your program has it open, that's a different story.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
void City::setNextCity(City city) {
    nextCities->push_back(&city);
};

You can't do it like that because the parameter is a copy of City class, and will be destroyed as soon as setNextCity() exits. You need to make list own all the memory so that it doesn't rely on anything outside of it.

Just off the top of my head this is how you will have to do it. Note that you will also have to add a copy constructor to City class.

void City::setNextCity(const City& cty) {
    nextCities->push_back(new City(cty) );
};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Programmers use code guards, sometimes called include guards, to avoid the problems with double inclusions. You will find them used in almost (if not all) the standard header files that are installed with your compiler. When used, they would prevent the problem like the example presented by evstevemd, above.

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

I don't think so.

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

Ok, got this figured out. You need to code a copy constructor for class win which will be called for push_back into the vector of win objects.

Whether it works the way you want it to, I don't know. But I got it to run without crashing.

class win
{
public:
    win(COORD org , COORD size, winStyle ws)
    {
       allocbuffer(org,size,ws);
    }
    win(const win& w)
    {
        allocbuffer(w._org,w._size,w._ws);
    }
    ~win();
    void addElement(CUIelement x){}
    const CHAR_INFO * getBuffer(); 
    void drawWin(HANDLE hOut);
    winStyle getWinStyle();
private:
    void allocbuffer(COORD org , COORD size, winStyle ws);
    CHAR_INFO * _buffer;
    COORD _org;	
    COORD _size;
    winStyle _ws; 
};

void win::allocbuffer(COORD org ,COORD size, winStyle ws)  
{
    _org = org;
    _size = size;
    _org = org;
    _buffer = new CHAR_INFO[size.X * size.Y];
    for (int y = 0; y < size.Y ; ++y) {
        for (int x = 0; x < size.X; ++x) {
            int offset = x+((size.X-1)*y);
            _buffer[offset].Char.AsciiChar = 0x23;
            _buffer[offset].Attributes = fWhite;
        }	
    }	
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Your program is trashing the stack and/or the heap somewhere. I compiled with vc++ 2010 express and it get assertion error when exiting the program.

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

Probably yes. Why don't you just try it and find out for yourself.

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

turbo c++ is an ancient compiler that uses obsolete c++ header files and follows obsolete c++ standards. Bring yourself into the 21st century and learn how to write modern c++ code.

That is one of the problems with learning to program using ancient turbo c and turbo c++. You switch to a modern compiler and you have to unlearn almost everything you thought you knew.

conio.h is specific to turbo c and Microsoft. Don't expect the rest of the world to follow suite.

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

>> I know but how do i implement this

Simple, just look at the delete flag

while (Read next record)
{
   if( delete flag not set)
      Print record
)
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

why do instructors insist on teaching while( !in.eof()) instead of while( getline(in, line) ) ? eof() doesn't work like that and cause the while loop to loop too many times.


You should probably attach the input file rather than trying to paste its contents into the editor because the editor. The file contents you posted does not contain tabs -- just spaces.

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

That's about the only way I know of to do it.

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

This is the basic idea, you might have to modify it to suit yourself, such as do error checking and trim whitespace from end of the mac address after extracting it from the line.

std::string foo(std::string search)
{

std::string line;
ifstream in("filename.txt");
while( getline(in, line) )
{
   size_t pos = line.find('\t');
   std::string mac = line.substr(0,line);
   if( mac == search )
   {
      return line.substr(pos+1);
   }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't use that compiler, but I know there are flags that will make it spit out more warnings and errors.

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

>>using hbg_cmpsc122::Fractions;

Fractions is not in namespace hbg_cmpsc122 because you have misspelled the class name. Pay closer attention to spelling and capitalization -- fraction is not the same thing as Fraction.

What compiler are you using? I'm on MS-Windows using vc++ 2010 Express and I get lots of error messages and warnings.

Also, delete line 4 in Fractions.h.

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

Why are you using low-level file i/o?? Just use FILE* and all will be ok. The only reason to use open() is when the compiler for the target operating system doesn't have FILE* and associated functions.

But to answer your question, lseek() returns the file offset.

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

I wouldn't bother learn 16-bit asm, go directly to 32-bit so that the program can use whatever memory is available on the computer. It's also somewhat easier -- with the flat memory model it is not necessary to change the value of ds segment because all data is in the same segment.

As for assemblers: either masm, nasm or tasm.

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

If your program has to do file i/o or displaying something on the screen then it has no choice but to call win32 api functions to do that. 32-bit programs can not access hardware unless its a kernel level program.

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

line 116: variables x and y have not been initialized to anything.

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

First you have to write an OnTimer() event handler. That is a function that you want MFC to call every second. This example has it in CMainFrame, but you can put it in any of the CWnd derived classes, such as CMyDialog. You can have up to 10 timer events active at the same time, so nIDEvent parameter just tells which event is being called. You set that event number when you start the timer, explained below.

void CMainFrame::OnTimer(UINT nIDEvent) 
{
   MessageBeep(0xFFFFFFFF);   // Beep
}

Next, you have to turn on the timer somewhere in the code.
m_nTimer = SetTimer(1, 2000, 0);

  • The first parameter is an id number that you want MFC to use to identify the timer event. The OnTimer() function will be passed that number (see above)
  • The second number is the number of milliseconds you want the timer event handler to be called. The example shows it wants the event to be fired every two seconds.
  • The last parameter is a pointer to the function you want to be called. If that parameter is 0 (or NULL) it is assumed to be the OnTimer() method of the MFC class in which SetTimer() is called. Otherwise, if the prameter is Not called then it can be any function you want. See the SetTimer link for a more detailed explaination.
  • The return value is the MFC id of the timer event, if SetTimer() is successful. Use this value to pass to KillTimer() to …
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

GetSystemMatrics() works for the display monitor only. You have to call other win32 api functions to get the informatgion you want. To get the window's height/width call GetWindowRect()

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

Create a timer event -- see MSDN for SetTimer() and OnTimer() methods.

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

First declare a structure that contains elments for street address, suburb, and price.

Then useing ifstream open and read the file.

I could write the code for you, but I won't. I wouldn't want to deprive you of the joy of doing that yourself :)

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

>> It should be a multiple of 4 bytes.
Depends on the compiler and how it aligns the structure object. You can change the alignment with most modern compilers so that it is 1, 2, 4, 8, 16, 32 etc aligned. The default alignment is compiler dependent too.

mrnutty commented: Thanks for the info. +5
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Q3: The author may be wrong. Wouldn't be the first time wrong info was printed in a book.

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

I would get the input data as a string, then check each character to see that it is a numeric digit 0-9 or a . for floats (and there can be only one dot in the string). If it passes that test then convert the string to a float.

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

Did you read this?, especially InsertMenuItem()

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

Your program will get a runtime error because vector entity doesn't have any elements, so all those assignments in lines 9-15 will fail.

>>if(strcmp((*tokens), ',')

If you only want to compare two single characters to see if they are the same then why use strcmp()?? Just use == operator to compare them

for(i=0; i<tokens->size(); i++)
    {
        for(j=0; j<7; j++)
        {
            matrix.push_back(vector <char*>());
            if(strcmp((*tokens)[i], entity[j])==0)
                do{
                    i++;
                    if( *tokens->at(i) == ',' || *tokens->at(i) == ';')
                         strcpy(temp, tokens->at(i));
                }while(*tokens->at(i) == ';');
        }        
    }
nirali7 commented: you're awesome!!! +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Its posted in the first post to this thread -- way over on Page 1.

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

Your program is also inconcistent in the way it declares std namespace. If you don't use using namespact std; or using std::vector; then you have to preface every instance of vector with std::, such as std::vector< std::vector< std::string> > something; As for the parameter tokens -- unless that is an array of std::vector objects, then it would be better to dealred it as a reference instead of a pointer -- std::vector<std::string>& tokens) . That would remove the ambiguity between passing a reference to a single vector object or passing an array of vector objects. Declaring it as a pointer we don't know which one you meant without seeing the function that calld it.

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

Compare the program I posted with what You posted. You failed to add { and } round that while statement, and the comparison on line 10 is still wrong.

You need to learn to pay more attention to the logic of your programs.

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

The formatting leaves something to be desired.
Variable numar needs to be initialized to some value greaterthan 0
The program is missing { and } around that multi-line while statement
The if and assignment statements are backwards

int main ()
{
    int numar = 1, biggest =0;
    cout<<"insert an integer ";
    while( numar > 0)
    {
        cin>>numar;
        if(biggest < numar)
        {
            biggest = numar;
        }
    }
    cout<<biggest;
    system("pause");
    return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

delete line 10

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

it doesn't work because you have to use sprintf() to format the string.

char command[255] = {0};
sprintf(command,"copy %s.jpg \\%s\\%s.jpg" , a, a, a);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Well, did we answer your question or not? If we did then please mark this thread Solved.

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

Didn't the example I posted help you? It contains one setter and three getters. If that isn't what you are asking then you need to explain yourself better and with example. The example you originally posted is almost identical to what I posted.

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


It does not. After vfork the parent process is blocked until the child does either _exit() or execve. Parent and child never run in parallel while sharing memory space.

I have no clue how vfork() works -- I was just comparing the posted results with how MS-Windows CreateThread() works. The test I posted and ran works just as you described for vfork() -- the win32 api function WaitForSingleObject() causes the thread to wait until the child thread terminates.

The point is that even though parent and child have distinct FILE objects, both of them refer to the same file obect in the kernel. The parent's ftell() obtains the read pointer from this shared object, which is of course affected by child's read().

But if that is the case they why are parent and child file pointers different on some operating systems and the same on others? (Note: I'm not trying to state an opinion here, but just asking a question from someone who is probably more knowledgable about this than I am.)

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

Is it possible to do what? There is no restriction on the number of getters you can put in a class.And you have to put { and } around all functions even if they are only one line. I always make one liners inline code instead of in an implemnentation file

class C3dshape
{
private:
   int mLength;
   int mWidth;
   int mDepth;
public:
   int getlength() {return mLength;}
   int getwidth() {return mWidth;}
   int getdepth() {return mDepth;}
   void setvalues(int Length,int Width, int Depth)
   {
      mLength = Length;
      mDepth = Depth;
      mWidth = Width;
   }
};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

MS-Windows creates threads just like vfork, where all threads share the same memory. I didn't realize fork() creates new data space :-O

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

Sorry, I don't understand your question.

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

The asterisk before the variable means to reference only the first character in the string that the variable points to. So if string = "1234", then *string is looking at '1'. Another way to say the same thing is *string it the same as string[0].

Consequently, *string - '0' is the same as '1' - '0', which if you look at any ascii chart '1' = 49, and '0' = 48. So it boils down to 49 - 48 = 1.

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

I much perfer this instead of all those shifts. The code below could fail for integer overflow.

int myatoi(const char *string){
   int i = 0;
    // skip leading white space
   while( isspace(*string))
      ++string;
   while(*string && isdigit(*string))
   {
       i = (i * 10) + *string - '0';
       ++string;
   }
   return i;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

We're not going to do your homework for you.

(1) if the head is NULL -- this is a simple assignment statement. allocate memory for the new node then assign its pointer to the list's head.

(2) head already exists: You want to add the new node to the tail of the list. The function needs to iterate through the nodes to find the last node, then assign the new node to the next pointer of the tail node. That makes the new node the new tail node.

(3) It doesn't matter what the node contains, the above two methods are always done the same way.

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

total+=y is the same as total = total + y. Just a shorthand way of saying it and either is perfectly acceptable.

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

Another name for it is "cursor". But MS-Windows calls it a caret for some ungodly reason. I always though a caret was something we eat.

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

Ok, here is a simple example that I whipped up in just a few minutes. It creates a vector of people structures then calls std::search_b() to find one of the objects.

#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

struct person
{
    string fname;
    string lname;
    void init(const char* f, const char*l)
    {
        fname = f;
        lname = l;
    }
};

bool compare1(person& p1, const char* value)
{
    return p1.fname == value;
}

bool compare2(person& p1, const char* value)
{
    return p1.lname == value;
}

int main()
{
    vector<person> people;
    person p;
    p.init("Jones","Tom");
    people.push_back(p);
    p.init("smith","Mary");
    people.push_back(p);
    p.init("Adams","Tom");
    people.push_back(p);
    p.init("Baker","Henry");
    people.push_back(p);
    vector<person>::iterator it = search_n(people.begin(),people.end(),1,"smith",compare1);
    if( it == people.end() )
    {
        cout << "Not found\n";
    }
    else
    {
        cout << "Found\n";
    }
	return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Nope. An array is not needed.

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

Don't write obfuscated code by defining standard C functions to have a different name. That's a very very bad coding style to do that, which might get you lower marks by your instructor.