Agni 370 Practically a Master Poster Featured Poster

Even then output might not be what you desire, getc returns the character currently pointed and also advances the position indicator by 1. so it'll always stub the first char from the output. since you're already checking for the 'eof' you dont need this extra check using getc. You can completely remove that while loop.

what was wrong with 'cout' though?

Agni 370 Practically a Master Poster Featured Poster

You need to include the file which declares cout,cin i.e. #include <iostream> and namespace 'std'. i dont think you need the stdafx.h at all.

and please read the welcome guide to understand the posting rules and regulations.

Agni 370 Practically a Master Poster Featured Poster

Hi Guys..

Can someone explain to me what's the difference between sending any data over a socket vs sending an http request? i mean sending an http request would also be happening over a TCP socket, am i right? so basically it's as simple as sending data from client socket to server socket but in a certain format and the server socket is also designed to accept that particular format, is that correct?

someone please clarify.

Agni 370 Practically a Master Poster Featured Poster

It could just hang waiting for some input which it's not getting, in that case we need to check the time elapsed and restart the program. Frankly speaking i cant think of a way to do it rt away, and i'm in a little hurry, but this was just to get AncientDragon thinking in this direction

Agni 370 Practically a Master Poster Featured Poster

Yes we did that, and then later in one of the files the includes were not proper. after doing that the code is working fine , atleast for now. We've decided to look into it in detail again in future. What it did though is that my interest in the curses library has grown and i downloaded it on my laptop and have started to use it. Going slightly off-topic can you suggest some cool things that i can try using curses, basically what is the main use of the curses library?

Agni 370 Practically a Master Poster Featured Poster

Hi Vijayan,

On some digging up i found that the window is not made up of garbage but rather from the values taken up from curses.h file.

#define ACS_HLINE NCURSES_ACS('q') /* horizontal line */
#define ACS_VLINE NCURSES_ACS('x') /* vertical line */

however we have written a wrapper around this and are setting our own values for these Macros

#define ACS_HLINE TEXT('-')

but these values are either getting over-written or not getting applied at all. Seems like some issue with how the files are included. I think it's a very intrinsic issue related to our code.

Thanks a lot for your time.

Agni 370 Practically a Master Poster Featured Poster

Hi,

We're using curses library functions to draw windows in our project. For showing an error the error message is enclosed within '-'s , it seems to be working fine till we ported to a new linux machine where its displaying some garbage instead of the '-' . To be honest the code is vast and i dont think there's anything wrong with it, seems like there's some configuration problem with some curses path. the ASCII value of '-' is defined in something like 'ACS_HLINE' macro.

i know there's very little info and not too clear. But this is the best i could get, if anyone has any clue please reply.

Agni 370 Practically a Master Poster Featured Poster

well you cant really name the elements of an array, they need to be accessed using the subscript.However to identify each object you can add a unique field in the class and set it for each object. Then when you fetch the object just check for that value to identify it. Or else use a map, so you can add a key for each object stored and then fetch it based on the key.

Agni 370 Practically a Master Poster Featured Poster

To iterate is human, To Recurr ... Divine

Read it in one of the c++ books.

Agni 370 Practically a Master Poster Featured Poster

That's true.. but what i meant was that may be the OP could tell us if either of this is right or not. Or probably Mr OP you can tell us what is it that you're trying to solve and then we might be able to point in the right direction.
I dont mind these answers though, Vijayan's example is very interesting and i'm still trying to understand that :) ...

Agni 370 Practically a Master Poster Featured Poster

Are we playing 'Read My Mind' here :) ...

Agni 370 Practically a Master Poster Featured Poster

I feel that for talking between different processes you will need to use CORBA(Common Object Request Broker Architecture). Atleast that's how we do it here, there might be other methods though. So basically what happens is, your servers register with the broker. Client request for the server object from broker. Once the broker returns the server object, the client then makes direct contact with the server. You will have to write CORBA classes for this, stubs and skeletons.

Agni 370 Practically a Master Poster Featured Poster

1-> What is the expected output?
2-> What's the output you're getting right now?
3-> Post the complete code
4-> Please use code tags to make you're code readable

Agni 370 Practically a Master Poster Featured Poster

>>I.e. if we open a text editor will we find threads inside?

Text editor will definitely be multithreaded. Imagine a scenario where you send one document for printing and are writing into another document. Almost every application we use in our day to day lives will be multithreaded. The fast CPU speeds, huge amount of RAM's in the systems today make it almost mandatory to write multithreaded code to take full advantage of the processor.

Agni 370 Practically a Master Poster Featured Poster

:) ... dude.... what do you mean by 'link classes' ?

Agni 370 Practically a Master Poster Featured Poster

what i think you're supposed to do is, you need to read some stuff about datatypes in c++ and then revisit the code.

Agni 370 Practically a Master Poster Featured Poster

arr is not an array its and int. line 40.

Agni 370 Practically a Master Poster Featured Poster

ur most welcome ...

Agni 370 Practically a Master Poster Featured Poster

Dont replace earnedAmount, just change this line in 'sodaDisplay' method

double earned = 0;

to

static double earned = 0;
Agni 370 Practically a Master Poster Featured Poster

You are initialising 'earnedAmount' to '0' in every call of 'sodaDisplay' method. It should be initialised only once. Make it static and try.

static double earned = 0;
Agni 370 Practically a Master Poster Featured Poster

i'm trying to execute this program and everytime it tells me the same thing..

Welcome to the imaginary drink machine!
Please choose your icey cool beverage!!
---------------------------------------
1. Cola $0.75
2. Root Beer $0.75
3. Lemon-Lime $0.75
4. Grape Soda $0.80
5. Cream Soda $0.80
6. Nothing thank you
-->1

You chose Cola! That will be .75 cents!
Please insert money (in 0.00 format):0.75
Now how did you manage to enter that?
Please enter a POSITIVE amount of money!

isn't 0.75 positive? moreover y should it ask me to enter the amount when it's already shows how much it costs? System can itself take that amount.

Agni 370 Practically a Master Poster Featured Poster

hi..can you please post the 'correct' version of code using code tags and also the errors in one single post. That ways it'll be easier for people who want to help.

Agni 370 Practically a Master Poster Featured Poster

that's exactly what he's done i guess ...

Agni 370 Practically a Master Poster Featured Poster

The definition can be in any file, since its not a class member. your code seems fine to me. inside the defintion, you can decide what all you need to output when you do cout << book.

ostream& operator <<(ostream& outs, const Book& b)
{
	
     outs << b.publisher << " " << b.title << " " << b.price << endl;
     return outs;
}
Agni 370 Practically a Master Poster Featured Poster

mostly this type of error comes when you are trying to access an index which doesnt exist in the vector. suppose you have only 5 elements in the vector and you try to fetch [5] or [6] element. in your sellstock method you are looping from 0-6, can you check if your vectors have enough elements? to make it better, you can get the 'size' of the vector and loop from 0-size.

Agni 370 Practically a Master Poster Featured Poster

Hi Guys...
i'm sure the topic has given you a braod hint and if u've still been brave enough to open this just help me out... i have a dual boot system, windows XP and Ubuntu 7.1. i need to change this setup to a virtual machine setup, host xp - guest ubuntu. incase you want to know y, just read on or else you can skip this part :) ... basically i'm not able to access wireless network on my ubuntu system, i'm going to do some development on ubuntu ... secondly virtual desktop sounds so cool(main reason) ... and then obviously it'll b gr8 coz' i'll have the powers of both the OS's at one time( and some weaknesses of XP too, but i'll bear those)....
Now what i really need to know is that should i uninstall ubuntu and then go ahead with virtualization or can i use the existing setup? which one of the ways would be easier and less error prone??

any suggestions are welcome...

Agni 370 Practically a Master Poster Featured Poster

hmm.. but what if i dont want to modify the db? .. isn't there a system view which has the state of the tables? .. adding a trigger on each table will make the system too slow, even for a development team....

Agni 370 Practically a Master Poster Featured Poster

Hi Guys...

i'm not so good at oracle, sql and related stuff.. but i do need to write some simple query's from time to time and i do need to understand that which all tables get updated by a particular transaction. I can do that by going through the code, but problem is i'm damn lazy and also that usually i like to automate most of this donkey work. would be great if any of you oracle guru's could tell me that is there someway i can find that which all tables got updated by a transaction. i expect some system view or some system table to contain the states of the tables(last modified) or something like that which i can query before and after i run a transaction or something on those lines.

Agni 370 Practically a Master Poster Featured Poster

is the stack.cpp also having a main?

Agni 370 Practically a Master Poster Featured Poster

doesnt work that way over here dude... sorry.

Agni 370 Practically a Master Poster Featured Poster

Hi..

i have installed Ubuntu 7.10 on my laptop. it also has windowXP installed. i'm able to access wireless network on windows but on ubuntu its not detecting it. when i connect it through a wire i'm able to access. i read on the net, seems my WAN card which i guess is a broadcom 4318 series is not supported and that i can apply a patch to make it work. can anyone throw some light on this?

edit: just to add that i have already installed the bcm4XXX firmware and related driver.

Agni 370 Practically a Master Poster Featured Poster

oops..i'm sorry, you are already doing that... i didnt read it properly :( ... but you dont have to read the file in both the loops. 2nd point still remains valid.

-> you have not opened the file. check ifstream::open and ifstream::is_open, ifstream::close methods.

Agni 370 Practically a Master Poster Featured Poster

couple of things...

1-> for loop needs to be nested. think about it, you are reading values into a 2D array so in the first loop you want to read row 0, all cols, hence the '[row]' index remains constant and you increment only cols. so you get a[0][0].a[0][1],a[0][2]. row remains constant, then once you are done with the first row. increment the 'row' index to point to next row, loop through cols. hope you got that. not the best of explanations i know.

2->when you do the first 2 reads from infile, you will get the row and col values. they should be put in I and J variables and then you should use I and J in the nested loop.

try to understand the working of this nested loop.

int matrix[2][3] = { {1,2,3},{4,4,5}};

int rows = 2;
int cols = 3;

for(int k=0;k<rows;k++)
{
   for(int l=0;i<cols;l++)
   {
        cout << matrix[k][l];
    }
}
Agni 370 Practically a Master Poster Featured Poster

you can do something like..

int rows=0;
int cols=0;
infile>>rows;
inflie>>cols;

this will give you the row and cols values. for taking array values use nested for loops

for(loop from 0 to rows)
for(loop from o-cols)
infile>>arr[rowcount][colcount]
endloop
endloop

try this. for removing the errors start with removing all silly errors like different spellings at time of declaration and definition, differnt case etc.

ex:

ifstream infile;
inFile.open("data1.txt");

'infile' and 'inFile' are not same, will throw error.

Agni 370 Practically a Master Poster Featured Poster

also having predator and 'prey' in life class n then in plants you are setting 'prey' as 'sun light' doesnt look too nice. you can have separate members for plant classes like 'energysource' or something, unless your assingment specifically asks you to use this.

Agni 370 Practically a Master Poster Featured Poster

again like i said you can explain anything but what if you write a code and someone has to understand it on his own? he might not be able to interpolate that life=world etc. anyways since i'm not able to suggest anything better i'll have to accept it.

to focus more on inheritance, i dont think that the 'life' should have a pure virtual method called 'eats', because plants dont eat as such and it would not be right to make every plant class implement the 'eats' method even though it doesnt use it. i think you can have one more layer of abstraction in between. from life you can inherit 'animalKingdom' and 'plantKingdom' classes and the put the 'eats' method in animalKingdom. for 'plantkingdom' you can have something like 'produces'. then derive all animals from 'animalkingdom' and plants from 'plantkingdom' and keep only the common functionality in the 'life' class.

Agni 370 Practically a Master Poster Featured Poster

i guess your first file should have these 2 lines

"3 3
1 2 3 4 5 6 7 8 9"


for a 3*3 matrix

1st line of the file gives you the number of rows(3) and number of cols(3) and the second line is givng row*col numbers. hence a[0][0] = 1,a[0][1]=2,a[0][2]=3,a[1][0]=4 so on and so forth.

you can read the row and col values into some variables and then the actual values into a 2D array.

Agni 370 Practically a Master Poster Featured Poster

doesnt seem good to me ... why is the base class named 'life'? and why does 'life' have a member function called 'eats' ? and then you have 'producers' and 'animals' deriving from life.. you might have some explanation for all the names and member functions. but you should always try to see that what would a complete stranger make out of the code by just reading it. for me, i dont understand the first inheritance step by just reading it and hence i didnt go any furthur.

Agni 370 Practically a Master Poster Featured Poster

:) .. yeah it's me ... was trying to get it changed to just 'chandra' but that wasnt available so now its a totally new one...

Agni 370 Practically a Master Poster Featured Poster

Thanks guys that worked... i think that was quite a decent mistake at this stage .... thanks again

-chandra

Agni 370 Practically a Master Poster Featured Poster

sorry, i forgot to mention that i tried that too but even that doesn't work. i dont think using char*'s is proving to be a good idea.

Agni 370 Practically a Master Poster Featured Poster

Hi..

whats the best way to initialize a char* ? i tried using char* p = ""; and it gives segmentation fault at times. not sure how to initialize it.

this is the function where i'm using it. screenReturnValue variable is not getting initialised properly everytime, when i call this method the second time it returns a value which is a concatanation of last value and current value.

char*
generateReturnValue(string screenClassName)
{
	char* screenReturnValue = "";
	char* ptr = "Ptr";
	strcat(screenReturnValue,screenClassName.c_str());
	strcat(screenReturnValue,ptr);
	return screenReturnValue;
}

thanks

Agni 370 Practically a Master Poster Featured Poster

really??? ... i need to pay more attention now ... i hope ancient dragon is a guy :) ....

Agni 370 Practically a Master Poster Featured Poster

yup.. i always thought you were a guy, couldnt make out much from the name 'narue' but i guess ur avtaar was some guy with a saw or something ... anyways its a pleasant surprise :) ....

Agni 370 Practically a Master Poster Featured Poster

i just wanted the 'rajat' removed from the name, this is my real name and my complete name too, thought it's not too cool to have the exact name on a forum and just the last name would be good ....

No, my real name is Julienne.

Narue, are you a girl? .. i always thought you were a guy....

Agni 370 Practically a Master Poster Featured Poster

just print out the array using 2 for loops.

something like

int a[m][n];
cout << "Name" << " " << "Total" << endl;
for(int i=0;i<m;i++)
{
     for(int j=0;j<n;j++)
     {
          cout << a[i][j] << " " ;
     }
   cout << endl;
}

do some formatting.

Salem commented: Say "Yes" to formatting +15
Agni 370 Practically a Master Poster Featured Poster

c++ is case sensitive

Agni 370 Practically a Master Poster Featured Poster

loads of examples available on this forum.. please use the search option.

Agni 370 Practically a Master Poster Featured Poster

you can use

system ("sh scriptname");

Agni 370 Practically a Master Poster Featured Poster

May be you can try using some of the standard lib methods like strtol,strtod, strtoul etc. i'm not sure which will be sufficient for this range of numbers.