dkalita 110 Posting Pro in Training

you can use

scanf("%[^\n]",...);

as well to scan a whole line.

Ancient Dragon commented: good point +36
dkalita 110 Posting Pro in Training

there is nothing in the outbuffer variable.
You are modifying the variable "outs" everytime. So reset it after every itereations to "".

When you wrote

ostringstream outs(outbuffer);

the outs variable is initialised with the string in the variable "outbuffer", it does not correlate to that variable.
So reset "outs". And at the end print outs.str() instead of "outbuffer".

dkalita 110 Posting Pro in Training
#include<iostream>
using namespace std;
int main()
{
   int *matrix;
   int dimension;
   /*read dimension first and initialise "dimension" and then allocate apropriate memory to "matrix" and then read the matrix into this array. This can also be done inside a function which will make your code more usable*/

   /*process the matrix, better write a function and pass the matrix to it and do the processing inside that.*/

  /*write back the new matrix data into the same file. This can also be put inside a function.*/
}

This is how you can start.
Write the fileRead, matrixProcess, and fileWrite method seperately and test them thoroughly before writing the next function.

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

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
int main()
{
    int two_d[10][20];
    return 0;
}

take it....

or else tell us what problem u are facing with 2d array.....

dkalita 110 Posting Pro in Training

tower of hanoi is a very good example for solving by recusrion.

Though recusrion is helpful at times while solving some very critical problems though it has some demerits. Read about recursion in more detail to know its merit and demerits.

dkalita 110 Posting Pro in Training

u r welcome

dkalita 110 Posting Pro in Training

hey thats the Counter class. Sorry I misspelled it.
Make it as

int Counter::count = 0;
Nick Evan commented: Simple fix, problem solved! +10
dkalita 110 Posting Pro in Training

u must intialize a static member.
Add the line

int Counter::count = 0;

before main() or other module where u are using or just after declaring your class.


A static data member must always be initialized before being used.

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

May be u can get some hint from this thread.
http://www.daniweb.com/forums/thread33551.html

Many of the machine info u can get from the files present in the following folder:

/proc/sys/kernel

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

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

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

Create a program that displays a pyramid , square and a triangle using the multiply character “*” as follows:
welcome to c++
shape for pyrasmid
sqyare
trinagle

In C++ u have so many features available such as: cout, for loop, etc.
Use them along with your brain. That will help get the solution.

If while coding u need some help, then go ahead, post your issues here. We are here to help u.

Show some effort then only we help.

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

how i can make compiler

google "compiler design"

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

ok ok.
make the following change
(refer to line #19)

if(start==FALSE && spacePrinted==FALSE)                
{
                       putchar(' ');
                       spacePrinted = TRUE;
}

change the above codes to

if(start==FALSE && spacePrinted==FALSE)                
{
                       putchar(' ');
}
spacePrinted = TRUE;
dkalita 110 Posting Pro in Training

hi there is already one library method in unistd.h called encrypt() hence it is giving the problem.
Change the function name to something else like encryptit().
It should work.

Sapreaver commented: Thank you +1
dkalita 110 Posting Pro in Training
if(number = 0){}

what do u expect it do do?
That is an assignment statement. Read how to compare numbers.....

U are doing

number = number%16;

u are getting the least significant digit by that and u are loosing the remaining number.
U should have done

digit = number%16;
number = number/16;
/*compare digit now*/

here is how u can solve your problem in short

void itox(char hex[], int num)
{
     int digit;
     int i=0;
     whle(num>0)
     {
        digit = num%16;
        num = num/16;
        if(digit<10)
              hex[i++] = digit + '0';
        else
             hex[i++] = digit -10 + 'A';
     }
     if(i==0)/*if the number was less than 1*/
        hex[i++] = '0';
     hex[i] = '\0';
     /*reverse the string*/
    reverseStr(hex);
}
void reverseStr(char str[])
{
   int i, j;
   char c;
   for(i=0, j=strlen(str)-1; i<j; i++, j--)
   {
      c = str[i];
      str[i] = str[j];
      str[j] = c;
   }
}
dkalita 110 Posting Pro in Training

please help for this code. if anyone have it please send me. thanks

IMPORTANT:
1. this is not a code repository.
2. We help those who show some effort.

dkalita 110 Posting Pro in Training
reverseArray(intArray,low,high);

what is the value of low and high. U didn't initialized them.
Would u plz first go through your code and do a dry run using pen and paper.

dkalita 110 Posting Pro in Training

use a flag for that as follows

#define FALSE 0
#define TRUE 1

void VymazBiele()
{
int c;
    int start= TRUE;
    while ( (c = getchar() ) != EOF )
    {
        if (isspace(c))
        {
          if(start==FALSE)
                 putchar(' ');
          while ( (c = getchar() ) != EOF && isspace(c))
          {}
          }
          if (c != EOF)
          {
                putchar(c);
                start = FALSE;
          }
    }
}
dkalita 110 Posting Pro in Training

needs to be .rtf because thats what apple uses as its texteditor

hi, I have tested it as .rtf also. And its still working.

dkalita 110 Posting Pro in Training

I am using xcode to run my program and it doesn't work it, i might have to try another program to run mine. what program are you using?

i am doing it in Linux using the default c++ compiler (c++ <sourcefile>) and its running smoothly. by the way i have changed the input file extension to "txt" and then tested.

dkalita 110 Posting Pro in Training

hi, i run your program and got the following output:

230.12we are in the loopwe are in the loopwe are in the loopwe are in the loop4

with input file as:
"input.txt":
23
.12
3
35
3
2
1
4
3
2
3
67
1
4

dkalita 110 Posting Pro in Training

look at the following

if( tmp1->surname > tmp2->surname)

thats not a way for comparing two strings. U r comparing the address of the string instead.

use strcmp() for that purpose

vmanes commented: Good catch, I was just looking at the list aspects. +5
dkalita 110 Posting Pro in Training

Hi!
I m getting difficulty in pointers can u help ?

follow the link
http://www.exforsys.com/tutorials/c-language/c-pointers.html

dkalita 110 Posting Pro in Training

Hmm..i tried but can't.
Perhaps can u give some hint? LOL

Thanks

i am doing for the 2nd highest. Do for the 3rd highest on your own. U can do it in a similar way as follows.

int score;
double score1st = -1;
double score2nd = -1;
for (int i = 0; i < numberOfStudents; i++)
  {
    cout << "Enter a student score: ";
    cin >> score;
     if (score1st < score)
    {
      score1st = score;
    }
     else if(score2nd < score)
          score2nd = score;
 }
dkalita 110 Posting Pro in Training

ok. i got ur point. but one more question plz. only one client needs to connect with the other client. or both of the clients need to call the command connect() ? in other words i need to send that socket to only 1 client or to the both?

don't do a connect() from a client to client directly.
A client will always connect to the central server. Design your protocol in a manner as follows:

client ----------- connect() ---------> server
........................................(add the incoming client socket to a list)
client <------(client socket list)--- server
client --------particular socket----> server
(choose from other socket list)
client <----------ack------------------ server
(now this client have the particular socket where to write which the other client will read from, so just start writting to this socket.)

**** The above is not a full fleged protocol because it is not sending any info to the other client.
So first design your protocol properly, then only u should go for the implementation.

U have to design different message formats, say MSG_ACK, MSG_SOCKLIST, MSG_TEXT, etc.

May that help.

adcodingmaster commented: a very good and detailed answer. i got that very clear now. thnx a lot sir +1
dkalita 110 Posting Pro in Training

use fork() to create a child process and in the child process use execv() to call the background process.
read about fork() and execv() and their usage.

it looks like

int child;
child=fork();

if(child==0)
{
      execv(............);
}
else
{
        /*current process*/
}
Ancient Dragon commented: Good answer :) +36
kvprajapati commented: Excellent! +18