dkalita 110 Posting Pro in Training

use while(1) loop and inside the loop read one character at a time.
Break from the loop on getting something other that 0-9.
Handle the space explicitly.
If the numbers are multi-digit numbers you will have to use temp buffer to store the number till u get a space.

WaltP commented: Terrible suggestion -4
dkalita 110 Posting Pro in Training

1- Most importantly, what u are doing here is not proper quick sort. Read about it.
2- I don't understand why you have sent the array as "*v[]". Why do you think u need that. Why not just "v[]".
3- Putting function prototype inside another function. Not a great way of writing good code.
4- Why use strcmp() for character values?

5- Use <code> tags </code>

dkalita 110 Posting Pro in Training

line# 15:
This is not the way you invoke a function.
You should first know how to do that. Please read more about functions.


Some more feedbacks:

line# 22 and 26:
How do you handle the loop if the number of rectangle is variable. Better have another argument in the function which gives the number of rectangles.

line# 30 through 33:
Why are you repeating the same statements 4 times. You could have used a "for" loop here as you did before.

dkalita 110 Posting Pro in Training

1>c:\users\ben\documents\university work\year 2\c++\code\myc++\spritelab\asteroidsgame.cpp(17): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\ben\documents\university work\year 2\c++\code\myc++\spritelab\asteroidsgame.cpp(17): error C2365: 'srand' : redefinition; previous definition was 'function'
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdlib.h(511) : see declaration of 'srand'

Error #1:
This is coming because C++ expects the programmer to do the necessary typecast.
In you case you should have written
srand((int)time(0));

Error #2, #3:
You are calling the srand() function in global scope which is not allowed. Any statement should be enclosed inside a function (e.g inside main())
If you try to call it globally, the compiler will try to interprete as a new function declaration and srand() is already declared in "stdlib.h"

dkalita 110 Posting Pro in Training

Its in C itself.
It is compiled and object is created which is archived in library.

dkalita 110 Posting Pro in Training

but my teacher wants a constructor and a destructor. So i guess i have to use pointers.

upto u.
U can keep your constructor/destructor where u might want to do something else, or yes, u can use pointers.

dkalita 110 Posting Pro in Training

how do i do this without changing it to a pointer? then i need to change all the remainder of my code and would have to use a iterator.

in that case just remove the statements in the constructor and destructor in your first approach. The constructor is automatically called when u declare the variable. And teh destructor will also be invoked when its scope is over. U dont need to worry about that.

dkalita 110 Posting Pro in Training

when u write

vector<int> pq;
vector<int> data;

the constructor gets invoke which is

vector<int>::vector();

In line #41, #42, #47, #48: what do u suppose u are doing.
Thats not the way how u invoke the constructor/destructor.

U could have done something like:

#ifndef MY_MIN_PQ_H
#define MY_MIN_PQ_H

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

class my_min_pq
{
public:
	//default constructor
	my_min_pq();

	//destructor 
	~my_min_pq();

	//insert element at end of sequence, and rearrange so minimum data at the front of array
	void enqueue(int data ,int priority);

	//removes data and priority from front of vector
	bool dequeue();

	//show structure based on priority where the smallest key is the first item outputted. 
	void show_pq_structure();

private: 
	//store priority
	vector<int> *pq;

	//store data
	vector<int> *data;

	//finds minimum priority value in array and swap positions of this priority index 
	//with the first index as well as data values
	void find_min();

};

my_min_pq::my_min_pq()
{
	pq = new vector<int>();
	data = new vector<int>();
}

my_min_pq::~my_min_pq()
{
	delete pq;
	delete data;
}
dkalita 110 Posting Pro in Training

then invoke the read() method before the loop to read the 1st 16 byte.
If u dont want to read the remaining till the end remove the while loop.
But I suppose U want to read the remaining also, then just keep them or make necessary change as u like to read.

dkalita 110 Posting Pro in Training

line #64: u are passing int * instead of int.
do as

PrintOutput(*c, *d);
dkalita 110 Posting Pro in Training

when do u suppose the control is coming to line #25?

dkalita 110 Posting Pro in Training

line #224:
U are getting the max node in the temp variable. But u have not put it in the particular location. No links assigned. !!!!!!!!!

* Instead of deleting the cur node, copy the maxnode data into cur node and delete the max node.

There may somemore error I dint checked all your code.

dkalita 110 Posting Pro in Training

good catch....

dkalita 110 Posting Pro in Training

The error u are getting is clear enough to know whats wrong. I didn't checked that before.

U are passing improper parameters to the Carbol2::gamber() function.
The expected param is an object of type Carbol2 but u are passing something else.

Change the protocol of the gamber method in Carbol2 so that it takes the parameter u want to pass.

dkalita 110 Posting Pro in Training

add the default constuctor in Carbol class.
Check the line:

Carbol2 ubjuct;

when u do this it invokes the default constructor of Carbol2 which is Carbol2::Carbol2()
and also the default constructor to the base class is invoked which does not exist.
You have to write the default constructor for the base class i.e. Carbol.
In Carbol class just add:

Carbol(){}

in the public scope.

cheers...

dkalita 110 Posting Pro in Training

in class AVLTree:
You are not initializing root.
Add a constructor and initialize the root with NULL in there.

AVLTree()
{
    root = NULL;
}
dkalita 110 Posting Pro in Training

U are making a shallow copy for Message while assigning it to the data.
U need to do a deep copy instead to retain the member data.
Overload the assignment operator for Message class and use strcpy() in it for copying each of the member.

There may be some more problems. But resolve this issue first.

dkalita 110 Posting Pro in Training

line 18: use the commented statement at line #15.
remove the semicolon at its end.
line #21: u are returning 0 on success. (0 is generally used as false)

dkalita 110 Posting Pro in Training

include stdbool.h

The type is "bool"

e.g.

#include<stdbool.h>

bool b= true;

this works in my compiler(cc).

Iam3R commented: Thanks +1
dkalita 110 Posting Pro in Training

what if node==NULL and
U are trying to access node->first i.e. member of an object that doesn't exist.
This will result in seg fault.

dkalita 110 Posting Pro in Training

everywhere u are accesing the members of some structure using pointer and there doesn't seem to be any check for NULL statemnt.

dkalita 110 Posting Pro in Training

that is called the arrow operator which is used to access the members of a class or a struct using a pointer.
Check the link
http://iqsoft.co.in/cpa/notes-cpp/structs/arrow.html

dkalita 110 Posting Pro in Training

ofcourse it wil crash because it is getting into an infinite loop because its not reaching the final condition.

make your condition from if(n==0) to if(n<1) in the factorial function

dkalita 110 Posting Pro in Training

the function fun() takes a funtion(whose return type is int and with no params) pointer as its argument.
And u are sending main to that funcion.
Thats it.
Read on pointer to function.

dkalita 110 Posting Pro in Training

But, is there any proposed solution to what I'm looking for?

use if() statement and strcmp() function for your purpose.

dkalita 110 Posting Pro in Training

its says the character 'a'.
Like we represent a string using double quote, e.g. "test string", we represent a character using single quote, e.g. 'a'.

dkalita 110 Posting Pro in Training
void f(int** a) //its a pointer to a pointer. The argument to the function f is a pointer to pointer
{
    cout << **a; //prints the value stored in a, output is 45
    cout << *a;   //address of the memory where 45 is stored
    cout << &a;   //address of variable 'a' (it will come as ***)
}

//I'm OK with main(). I'm including it FYI
int main()
{
    int i = 45;
    int* ptr = &i;
    f(&i);/*u r passing incorrect arg*/
             /*passing 'int *' instead of 'int **'*/
              /*should have called as:  f(&ptr);*/
}

EDIT: correction
line #5: its "int ***" and not simply "***" in the comment.

necrolin commented: Thank you +1
dkalita 110 Posting Pro in Training

remove the -ansi option while compilation. Just do
gcc -Wall client.c

BestJewSinceJC commented: Thanks! Wish I could give you more rep. +4
dkalita 110 Posting Pro in Training

Hi, I compiled that file (client) and I am not getting any error . !!!!!!
I used cc compiler and compiled on the following OS

Linux mymachine 2.4.20-28.9.XFS1.3.1smp #1 SMP Mon Jan 5 13:20:15 CST 2004 i686 athlon i386 GNU/Linux
dkalita 110 Posting Pro in Training

yes.
That is iterpreted and processed by the shell which sets the argv and forward to the executable binary file.

dkalita 110 Posting Pro in Training

How to:
1. Buffer output ?
2. Get its size ?
3. Print the buffer ?

#include <stdio.h>

int main(void)
{
	printf("Tons of printf lines\n");

	// 1. Somehow buffer the output up until this point

	printf("The size of the buffer is: %i\n", SIZEOFBUFFER); // 2. Get and print the size of the buffer.

	printf("Here is the output:\n\n%s", BUFFER); // 3. Print the buffer.

	return 0;
}

may be something like

#define MAX_BUFFER 1000
char BUFFER[MAX_BUFFER];
BUFFER[0] = '\0';
strcat(BUFFER, toPrint);/*toPrint contains whatever u wanted to print*/
/*but check for the buffer content size because if it exceed MAX_BUFFER u wil get seg fault*/
/*do it for every printf("%s", toPrint)*/
printf("The size of the buffer is: %i\n", strlen(BUFFER)); // 2. Get and print the size of the buffer.
printf("Here is the output:\n\n%s", BUFFER); // 3. Print the buffer.
dkalita 110 Posting Pro in Training

The function main in myprog will receive a char** argv containing the following strings

"-z", "hello", "-m", "this is a message"

One small correction.
char** argv will contain

"myprog", "-z", "hello", "-m", "this is a message"

So there must be somewhere in a C library a function which takes the command line string and produces the char** argv.
My question for you, C experts, is where is this function and how is it called ?

I guess this part is done by the OS rather than a compiler.

dkalita 110 Posting Pro in Training

u have to draw the left side line and right side line in the same loop by printing col number of spaces in between

dkalita 110 Posting Pro in Training

Just explore this site a bit.
Infix to postfix conversion has been discussed earlier in many threads.

dkalita 110 Posting Pro in Training

please mark te thread as solved if u think its solved......thanks........n welcome.....

dkalita 110 Posting Pro in Training

u haven't initialized the variables
myLineNumbers and temp

and u are trying to operate on it.

Initialize them in the constructor as:

myLineNumbers = new Queue<int>();
temp = new Queue<int>();
dkalita 110 Posting Pro in Training

i am not sure but it might be
friend ostream& operator<< (ostream &, const GrabStuff&);
needs a space between operator and <<
so it would be
friend ostream& operator << (ostream &, const GrabStuff&);

That is not an issue. I dont know why that error is coming though but I have tested it without space and works fine.


Error 2>

ostream& operator<< (ostream &os, const GrabStuff &name)
{
	os << name.myWord << " ";
	while (!myLineNumbers.isEmpty()) /*IN THIS LINE*******/
	{
		// blahblah		
	}
	return os;
}

Should have done

while (!name.myLineNumbers.isEmpty())
crystality commented: fixed my problem +0
dkalita 110 Posting Pro in Training

1> Once the default case is invoked, the flag rightanswer is set to false and it is never reset to true so that the loop ends.

2> U are trying to assign a string using = operator. Use strcpy().

dkalita 110 Posting Pro in Training

its because of the endianness. Read about Little endian and big endian theory.

hmortensen commented: short and on the issue. +1
dkalita 110 Posting Pro in Training

>Firstly, why is this?

It's because u are defining dictionary in more than one place
Once in wermz.cpp and once in main.cpp

>Secondly, why does it say .bss+0x0 and not the line number?

It's the object module which is a binary file and hence it doesn't have a line number

dkalita 110 Posting Pro in Training

i think u should do something like

class cstring
{
        char *str;
public:
        cstring(const char *str)
        {
                this->str = (char *)malloc(strlen(str)+1);
                strcpy(this->str, str);
        }
        cstring(const cstring &cs)
        {
                this->str = (char *)malloc(strlen(cs.str)+1);
                strcpy(this->str, cs.str);
        }
        bool operator>(const cstring &b)
        {
                if(strcmp(str, b.str)>0)
                        return true;
                return false;
        }

        /*some more members*/
};



/*use it as*/
treeNode<cstring> tree;

I don't think c++ allows u to overload any operator for 'char *'.
For overloading, the arguments must be either of class type or enumerated type(Am not sure what does it mean by enumerated type though).

dkalita 110 Posting Pro in Training

man many many many thankssssssss, you rock
the only thing i have to do now is to get it find
the shortest path and when find in the end to say
you escaped.
you helped me so mush, now i'm gonna
developing it every single day until perfection.
THANKSSSSSSSSSS!!!!!!!!!!!!!!!!!

u welcome.

And mark it as solved so that others dont' waste their time on a solved thread. :)

dkalita 110 Posting Pro in Training

write your own functions for validation.
e.g.

bool isnum(char *str)
{
       if(str==NULL)
            return false;
       while(*str)
       {
           if(!isdigit(*str))
                  return false;
           str++;
       }
        return true;
}
dkalita 110 Posting Pro in Training

here is another good approach

#include<ncurses.h>
#include<curses.h>

typedef struct
{
        int x;
        int y;
}coord;

int bitmaprow=22, bitmapcol=30;
int bitmap[22][30]={
                        {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1},                        {1,0,0,0,0,0,0,0,0,0,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1},
{1,0,1,1,1,1,1,1,1,0,1,1,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,1,1,1},
{1,0,1,0,0,0,0,0,0,0,1,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1},
{1,0,1,0,1,1,1,1,1,0,1,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1},
{1,0,1,0,1,1,1,1,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1},
{1,0,1,0,0,0,0,0,0,0,1,1,0,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1},
{1,0,1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1},
{1,0,1,0,1,1,1,1,1,1,1,0,0,0,0,1,0,0,0,0,0,0,0,1,1,0,1,1,1,1},
{1,0,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1},
{1,0,1,1,1,1,1,1,1,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1},
{1,0,1,1,1,1,1,0,0,0,0,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1},
{1,0,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1},
{1,0,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1},
{1,0,1,1,1,1,1,1,1,1,0,0,0,1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1},
{1,0,1,1,1,1,1,1,0,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1},
{1,0,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1},
{1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,0,1,1,1,1},
{1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1},
{1,1,1,1,1,1,1,1,0,1,1,1,1,1,0,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
};


int mazesize;
coord *maze;

void loadMaze();
void drawMaze();
int isOccupied(int x, int y);
int main()
{
        mazesize = bitmaprow*bitmapcol;
        maze =(coord *)malloc(mazesize*sizeof(coord));
        int x = 21;
        int y = 1;
        int maxx=bitmaprow;
        int maxy=bitmapcol;
        int ch;
        initscr();
        noecho();

        keypad(stdscr, true);
        loadMaze();
        drawMaze();
        move(x, y);
        printw("M");
        refresh();
        int px, py;
        do
        {
                ch = getch();
                px = x;
                py = y;
                switch(ch)
                {
                        case KEY_UP: if(x>0)x--; break;
                        case KEY_DOWN: if(x<maxx-1)x++; break;
                        case KEY_LEFT: if(y>0)y--; break;
                        case KEY_RIGHT: if(y<maxy-1)y++; break;
                }
                if(isOccupied(x, y)==0)
                {
                        move(px, py);
                        printw(" ");
                        move(x, y);
                        printw("M");
                        refresh();
                }
                else
                {
                        x = px; y = py;
                }
        }while(ch!='s');
        return 0;
}
void drawMaze()
{
        int i;
        for(i=0;i<mazesize;i++)
        {
                move(maze[i].x, maze[i].y);
                printw("*");
        }
}
int isOccupied(int x, int y)
{
        int i;
        for(i=0;i<mazesize;i++)
        {
                if(x == maze[i].x && y == maze[i].y)
                        return 1;
        }
        return 0;
}
void loadMaze()
{
        static int isLoaded = 0;
        if(isLoaded == 1)
                return;
        int count = 0;
        int i,j;
        for(i=0;i<bitmaprow;i++)
                for(j=0;j<bitmapcol;j++)
                        if(bitmap[i][j]==1)
                        {
                                maze[count].x = i;
                                maze[count].y = j;
                                count++;
                        }
        isLoaded = 1;
}
dkalita 110 Posting Pro in Training

one correction to my previous post:

do something like:

typedef struct
{
        int x;
        int y;
}coord;

/*store the coordinate of the maze as follows in an array*/
coord maze[]={{1,1},{1,2},{1,3},{1,5},{2,3}, {1,4}};
int mazesize = sizeof(maze)/sizeof(coord);/*hence u won't need to count how many coords are there manually*/

void drawMaze()/*draw the maze*/
{
        int i;
        for(i=0;i<mazesize;i++)
        {
                move(maze[i].x, maze[i].y);
                printw("*");
        }
}

call the above function before displaying the M ion the loop.
correst: call the above function only once in the beginning

int main(int argc, char **argv)
{
    int X = 10;
    int Y = 10;
    int ch;
    initscr();
    noecho();
    keypad(stdscr,TRUE);
    drawMaze();/*******here***********/
    move(Y, X);
    printw("M");
    refresh();
    do
    {
        ch = getch();
        move(Y, X);
        printw(" ");
        switch(ch)
        {
	    case KEY_UP: Y--; break;
            case KEY_DOWN: Y++; break;
            case KEY_LEFT: X--; break;
            case KEY_RIGHT: X++; break;
        }
       // drawMaze();/************here*******NOT REQUIRED*******/

        /****FIRST VALIDATE THE MOVE*****/
        move(Y, X);
        printw("M");
        refresh();
    }     
    while (ch!=27);
    endwin();
    return 0;
}

but now u have to check for a valid move also because that position may be a blockage(i.e. occupied by '*').
So write a function to validate your move and then ony execute the requested move.

call the drawMaze() method only once in the start. No need to call it on every move because it will be there at the console already.

panagos commented: ++ +0
dkalita 110 Posting Pro in Training

do something like:

typedef struct
{
        int x;
        int y;
}coord;

/*store the coordinate of the maze as follows in an array*/
coord maze[]={{1,1},{1,2},{1,3},{1,5},{2,3}, {1,4}};
int mazesize = sizeof(maze)/sizeof(coord);/*hence u won't need to count how many coords are there manually*/

void drawMaze()/*draw the maze*/
{
        int i;
        for(i=0;i<mazesize;i++)
        {
                move(maze[i].x, maze[i].y);
                printw("*");
        }
}

call the above function before displaying the M ion the loop.

int main(int argc, char **argv)
{
    int X = 10;
    int Y = 10;
    int ch;
    initscr();
    noecho();
    keypad(stdscr,TRUE);
    drawMaze();/*******here***********/
    move(Y, X);
    printw("M");
    refresh();
    do
    {
        ch = getch();
        move(Y, X);
        printw(" ");
        switch(ch)
        {
	    case KEY_UP: Y--; break;
            case KEY_DOWN: Y++; break;
            case KEY_LEFT: X--; break;
            case KEY_RIGHT: X++; break;
        }
        drawMaze();/************here**************/

        /****FIRST VALIDATE THE MOVE*****/
        move(Y, X);
        printw("M");
        refresh();
    }     
    while (ch!=27);
    endwin();
    return 0;
}

but now u have to check for a valid move also because that position may be a blockage(i.e. occupied by '*').
So write a function to validate your move and then ony execute the requested move.

dkalita 110 Posting Pro in Training

Thanks you have been quite helpful :)

and plz mark the thread as solved if u feel u are answered so that others dont waste their time in a solved thread. :)

dkalita 110 Posting Pro in Training

How ? Can you send me any example links :)

Thanks

char block[1000];

ifstream myFile ("data.bin", ios::in | ios::binary);
myFile.read (block, 1000);

see
http://www.angelfire.com/country/aldev0/cpphowto/cpp_BinaryFileIO.html

dkalita 110 Posting Pro in Training

regarding increasing efficiency:

Every time u invoke getline() method to read something from the file.
If the file have say 10,00,000 words u are executing getline() that many time. Now getline() involves file-read operation which is a time consuming task and hence it decreases the efficiency.

What u can do instead is read a block of data into a string (of say 1,000 character) and do whatever processing u need to do with the words in it and when u are finished with that block read the next block.
U will see the improvement in efficiency in this way.

dkalita 110 Posting Pro in Training

Also, this is for another assignment but what about arpa/inet.h or sys/socket.h? Are those also only supported by unix-like systems?

Yes.