dkalita 110 Posting Pro in Training

use ofstream class and write to file.

dkalita 110 Posting Pro in Training

u can try this

char cmd[100];
strcpy(cmd, "mkdir ");
strcat(cmd, dirName);
system(cmd);

strcpy(cmd, "mv ");
strcat(cmd, fileName);
strcat(cmd, " ");
strcat(cmd, dirName);
strcat(cmd, "\\");
strcat(cmd, fileName);
system(cmd);

Correct if I am wrong somewhere.
My point is u can use the system() function for your purpose.

dkalita 110 Posting Pro in Training

-----------sorry double post..............ignore this

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

Don't listen to dkalite. getch() is not standard, getchar() is.

Thanks for the correction but may I know the hazards or any side-effect of using getch() it in TurboC.

Using getchar() we have to press the enter key but using getch() we can just press any key then why getchar() instead of getch().

dkalita 110 Posting Pro in Training
name2 = givenLast + “,” + givenFirst;

givenLast and givenFirst are not initialized.

dkalita 110 Posting Pro in Training
for(unsigned i = 0; i < cantidad_frases; i++)
    {
        for(; *frases[i]; frases[i]++)
        {
            *frases[i] = getchar();
        }
    }

U have not assigned memory to frases.

Do

#define MAX_STR 40 // whatever u want
frases[i] = malloc(MAX_STR);

U are alos doing another mistake:

for(; *frases[i]; frases[i]++)

here frases is getting incremented. Hence the pointer advances and when later u want the inputed string u wont have it because the pointer has advanced to the end hence it contain nothing. U should do this with some temp pointer as

for(unsigned i = 0; i < cantidad_frases; i++)
    {
        frases[i] = malloc(MAX_STR);
        char *tmp = frases[i];
        for(; *tmp; tmp++)//AGAIN HERE U SHOULD MODIFY YOUR LOGIC BECAUSE frases[i] initially contains nothing. I am leaving it to you.
        {
            *tmp = getchar();
        }
    }
dkalita 110 Posting Pro in Training

Hi .
i am using C++ editor to write my C code.
when i press Ctrl+F9 , the output screen comes and goes without stopping for a while.

Please note that i have included "#include<stdio.h>" and i am using "getchar()" function do stop the screen.

If you are using turbo C then use getch() not getchar(). Its in the header file conio.h.

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

error 1:

/*you are writting*/
secretType () //default constructor
{name = " "; age = 0; weight = 0; height = 0;}
/*remember your 'name' var was like: char name[10]*/
/*but you are assigning it a value which is an address to a string of size 2 i.e. " ". one space and the \0 character.*/
/*This is not a way how u can copy one string to other*/

use strcpy()


error 2:

/*your prototype is*/
char setName ();

/*but u are defining another member as:*/
char secretType::getName(char name)

check the difference yourself.

And anyways, I guess you are trying to set the name which is a string and not a character, so your prototype should be like

void setName(const char *name);
dkalita 110 Posting Pro in Training

Below is an idea that u can apply. It is not the complete implementation. U can use this approach may be with some minute modification.

typedef enum
{_INT, _FLOAT, _OTHER} DataType;

typedef struct
{
       DataType dataType;
       union
       {
               int intData;
               float flData;
       } data;
}Data;

DataType getType(char *)
{
     /*implement yourself*/
     /*should return the datatype*/
}
float getFloat(char *)
{
     /*implement yourself*/
     /*should return the float equivalent of the string*/
}

vector<Data> dataList;

/*processing single line*/
DataType _type;
Data tmp;
char *tok = strtok(line, " ");
while(tok)
{
          _type = getType(tok);
          if(_type == _INT)
          {
                tmp.dataType = _INT;
                tmp.data.intData = atoi(tok); 
          }
          else if(_type == _FLOAT)
          {
                tmp.dataType = _FLOAT;
                tmp.data.flData = getFloat(tok); 
          }
          else
          {
                /*ERROR TYPE....HANDLE ERROR*/
           }
          dataList.push_back(tmp);
          tok = strtok(NULL, " ");
}

This was just one way. There are more than one way to do this job.

dkalita 110 Posting Pro in Training

post the code segment and the error u r getting.

dkalita 110 Posting Pro in Training

code snippet 1: line #24

u are not printing the value.

/**do it as follows/
cout << "Your number doubled is: " <<number<< endl;

code snippet 2: line #4

sysntax error

/*correct  form is*/
class Number{/*() not required*/
}
dkalita 110 Posting Pro in Training

let us see what errors u are getting

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

i have done a bit work on it. Check it out.
There is a hell lot scope for optimizing your code.
Go thru it and u will know where u can put functions.

dkalita 110 Posting Pro in Training

.

dkalita 110 Posting Pro in Training

than what command should i use to get the error

it should print the error by default.

dkalita 110 Posting Pro in Training

How can we get the last error occured in linux.
suppose there is a connect() func error in that case how to get the error that occured.

use gdb to get to the particular statement where the error ocurred.

dkalita 110 Posting Pro in Training

may be u can try this

char cmd[200];
strcpy(cmd, "ls ");
strcat(cmd, pattern);
strcat(cmd, " ");
strcat(cmd, "> itemlist.tmp");
system(cmd);

/*parse the file 'itemlist.tmp' to get all the matching items*/
/*u can use the 'file' command to get info about the item*/
/*or instead of ls u can use 'ls -ltr' which will give all the info. U just need to parse the output properly*/
dkalita 110 Posting Pro in Training

Is there any way to dynamically assign the length of the arrays depending on the input? That was what I was trying to do with the code below.

fscanf(infile,"%d", &numSegs);	
  char arrOwner[numSegs];
  char arrLength[numSegs];

use malloc()

char *arrOwner
char *arrLength;
fscanf(infile,"%d", &numSegs);	
arrOwner = malloc(numSegs);
arrLength = malloc(numSegs);
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

I found a way around it though. Turns out I needed to use template specialization. After reading through how to do that it works fine.

hey yes
You can do that.

dkalita 110 Posting Pro in Training

imp: line #35-37 (in the 1st code block)

the syntax is not like that as u have written. Its like

class Admin:public Person
{
/*members*/
};
dkalita 110 Posting Pro in Training

it would be like

class Person
{
/*members*/
public:
        void setName();
/*and more*/
};

class Admin:public Person
{
/*more members*/
};


/*u can use them as*/
Admin adm;
adm.setName("Testname");
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

compile as

c++ fileX.cpp fileA.cpp

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

are u looking for assignments?

If so u can try implementing the complex data structures like BST, avl tree, etc.
U will will get to learn many thing out of it.

dkalita 110 Posting Pro in Training

i would like to know the way we can make user enter a number in a menu reply perhaps so that he doesnt have to press the enter key...........i.e. the program automatically proceeds with the give value and doesnt wait for an enter key to be pressed. its easy in foxpro but i dont know the way to do it in C.

use getch()

dkalita 110 Posting Pro in Training

how i can make compiler

google "compiler design"

dkalita 110 Posting Pro in Training

Wow. That link is perfect! Thank you very much. I'll read that, and if I have any questions, I'll be sure to post them.

thats good...

dkalita 110 Posting Pro in Training

Glad to have u here, will u tell us something more about yourself?

hey plz ask anything that anyone want to know.......i am here to reply.... :)

and thankyou for the welcome......

dkalita 110 Posting Pro in Training

thanks for your answer.
so if i have a function and a pointer . i want to point that pointer to that function,how must i do?

read about pointer to function
http://publications.gbdirect.co.uk/c_book/chapter5/function_pointers.html

a small example:

int myfun(int par)
{
   return par+1;
}
int main()
{
    int (*fptr)(int); //pointer to function
    fptr = myfun; //assigning the function to the pointer
    (*fptr)(3); //calling the function using pointer
 // OR
    fptr(3);
}
dkalita 110 Posting Pro in Training

get the digits and their position and print accordingly.

e.g. say 1305.

3 in location 100 hence print "three hundred".

proceed accordingly for the rest.

DONT EXPECT READY-MADE CODE HERE

dkalita 110 Posting Pro in Training

please tell me about some my questions.
if (we have a pointer *tmp)-> that my goal is assign that pointer for another pointer ** temp ;
so ,how do we assign for right sytax.

are u asking something like

int y;
int *p;
int **pp;
p = &y;
pp = &p;
dkalita 110 Posting Pro in Training

This is what I guess it means

prev==0 means: Last entry to the bridge was from the NORTH
prev==1 means: from SOUTH

void enter_bridge_north()
  {
    num_waiting_north++; //add yourself to the waiting queue
    while (on_bridge || (prev == 0 && num_waiting_south > 0))
/*
*if someone on bridge
*OR
*previous entry was from NORTH and there are people 
*on the SOUTH waiting
*/
      ok_to_cross.wait(); //just wait till the above condition is true
    num_waiting_north--;//Enter the bridge. U r no more waiting, but not finished crossing
    prev = 0; //previous use was from NORTH
  }
dkalita 110 Posting Pro in Training
dkalita 110 Posting Pro in Training

Hi

I have joined this community one month ago and have become fan of it. This is the first and only forum where I registered and active since joining.

About myself:
I am Dharmendra kalita, from Assam, (India).
Currently doing as a trainee in GE Healthcare bangalore(India).
I have passed out of my university this year(2009) in June and from then I am here in Bangalore in this company.

I wish to go places in future. I love adventures (though I didn't had much opportunity to involve myself). I love video games(specially Counter strike).
I love helping people in whatever way I can.

And above all, I love programming, specially systems programming.

I have learned so much in here from the various discussions and hope I will learn a lot in future.

Thankyou

dkalita 110 Posting Pro in Training

U have not initialized your list.
In line #17 do

node *list = NULL;
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

the data variables can be defined virtual but is there a way to declare dat member not function virtual?this is my problem.

If u dont declare them as virtual and u try to access the derived class member then it will invoke the base class member only.
e.g.

class base
{
public:
   virtual void fun()
   {
         /*do something*/
   }
};
class derived:public base
{
public:
   void fun()
   {
    /*do something else*/
   }
};

base *bptr = new derived();
bptr->fun();
/*this will invoke the derived class member.(derived::fun())*/
/*But if u remove the keyword virtual in base class, it will invoke the base class member(base::fun()).*/
dkalita 110 Posting Pro in Training

I didn't get what u are trying to do. But let me explain a bit of inheritance

class Base
{
/*members*/
};

class Derived:public Base
{
/*members*/
};

Base *bptr = new Derived();
/*or if u need only base object*/
bptr = new Base();

But using bptr u wont' be able to access the mebers of Derived class untill and unless they are declared in the Base class as virtual and overridden in the derived class.

Read on inheritance.

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,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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
Matrix & operator+(const Matrix &, const Matrix &);

this is not the prototype for overloading binary operator.
The proper is

Matrix & operator+(const Matrix &);

The other operand for the operation is the calling object.

say

Matrix a, b, c;

c = a+b;

here the operator + is being invoked by the object a.
i.e. a.operator+(b)

U have to add the matrix b to a and return the sum which will get assigned to matrix c.


and what do expect the following statement to do???????????????

temp(r,c)=s.getelement(r,c)+ t.getelement(r,c)
dkalita 110 Posting Pro in Training

client

string s = "Who are you?";
/* transfer data */
		write ( sockfd, s, s.size() ); //--compile error
		nread = read ( sockfd, buf, SIZE );
		write ( 1, buf, nread );
		close ( sockfd );
		exit (0);

there is a compiling error in the client.

invalid conversion from ‘char’ to ‘const void*’
BasicClient.c:39: error: initializing argument 2 of ‘ssize_t write(int, const void*, size_t)’

use the methods send() and recv() for reading/writting to socket.

In write u are passing a string variable whereas it should be a const void *.
u should have tried

char *s = "Who are you?";
write ( sockfd, (void *)s, strlen(s) );