thekashyap 193 Practically a Posting Shark

Don't know the answer to your question. But won't it be fun to write it? :)
I think a tree would be quite suitable.

thekashyap 193 Practically a Posting Shark

1. I wonder why things work without linking to /usr/local/sesam/lib/libssv.so if you need it.
And if links without it I wonder why you need it.
2. Compare the size/timestamp of your mate's lib and your lib (/usr/lib/libstdc++-libc6.1-1.so.2). I think comparing the symbol table would be an overkill if size/timestamp are same.
3. Can't really say much except that when you link with ssv, the symbols needed by it are not available so it gives errors ! But I think it's pretty obvious.. :)

It does seem like the symbols you need might be there in stdc++. But you can confirm it once. So what you can do is:
- "ldd prog" on mate's comp
- then look for one of the symbols say "terminate(void)" in all .so files listed there. (donno what's teh command to list all symbols in a .so in gnu. In Sun workshop it's nm -C, so it goes like this: nm -C <xxx.so>| grep "terminate")
- Then find the same .so on your machine and check that it also contains the symbols, if it does link with it, if it doesn't it's a problem with your installation/version..

Lastly, check the documentation of your STL impl. Usually if you link to .so(s) specified there things should work.

thekashyap 193 Practically a Posting Shark

What's the problem ?
See help on code tags, would be more readable if you add =java.

thekashyap 193 Practically a Posting Shark

>> what does it mean to say we have a 32-bit processor ?!!
In very dummy terms it means the processor would process 32-bits in one machine cycle. Say if it's 2GHz processor, it'll process 32-bits 2 giga-times a second.

A 32 bit processor can address upto 32 bit long memory addresses. This directly translates to virtual memory space of 2^32.

thekashyap 193 Practically a Posting Shark

Probably Web Design is more appropriate forum for this query.
Not being a web-developer/expert my guess would be that JSP for front-end and Apache as a web-server should do your work.
Looking at your problem stmt there doesn't seem to be much business logic and given a local network there won't be many security/authorization issues as well. So you don't really need an App Server like JBoss/web-sphear..

thekashyap 193 Practically a Posting Shark

Problem is you're copying old to new, whereas what you want to do is new to old. Also using wrong formatting in printf().

See the comments inside the code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

//to avoid hard coding.
#define MY_MSG_LEN 100

int main(void)
{
    char oldMsg[MY_MSG_LEN], newMsg[MY_MSG_LEN];
    int len_newMsg = 0, i ;
    //not required to hardcode the length of "Hello World!", use strlen() instead
    //int cd = 12, cu = 0;
    strcpy(newMsg, "Hello World!");

    // -1 to discount the null char, which we'll still like to have at the end
    //and not at the begenning of oldMsg.
    len_newMsg = strlen( newMsg ) - 1 ;

//copy the other way around.
/*    while (cd > 0)
    {
          newMsg[cu] = oldMsg[cd];
          cu++;
          cd--;
    }
*/
    for( i = 0; i <= len_newMsg; i++ )
       oldMsg[i] = newMsg[len_newMsg-i] ; //copy backwards

    //last char should be a null char
    oldMsg[len_newMsg+1] = '\0' ;

    //%c is for a single character, %s is for a c-style char string
    //printf("%c", newMsg);
    printf("%s", oldMsg);

    printf("\n\nPress ENTER to end . . .");
    getchar();

    return 0;
}
thekashyap 193 Practically a Posting Shark

No way I can understand so much of code without code tags..

thekashyap 193 Practically a Posting Shark

How to pass char* as refrence in a funstion?

based on these two methods is there any gain over one, is one safer than another?

thanks

Seems like someone asked the question, some else read read the answers and followed up with more question and finally someone understood all and thanked. :)
If solved mark the thread as solved..

thekashyap 193 Practically a Posting Shark

And most smokers are genuine nice people like yourself, who do care for others around them, but a proportion of smokers are just plane idiots who don't give a care in the world, and when they puff the smoke out, it goes right into your face. It's those sort of people that i just want to punch in the face quite honestly! And i'm not violent!

Hmm, so it seems like there are lotsa "nice" smokers around.. :).
Just the same way I tried saying that even though there are times when smokers are smoking in their smoking corners, and still ppl have to make faces. It's those faces I would also like to break, no that I'm violent by nature.. :)

Discrimination, probably, but more importantly the government is trying to force you to stop smoking. The same thing if happening here in USA. And it is a little interesting that governments would force the closure of legitimate industry and put thousands of people out of work.

When a wife can't make a smoker quit, what chance a govt. got ?!

>>Medically, it's not.
So smoking is not a self-provoked death?
No

>Remember I have not even mentioned places like Hospitals and Schools
I hope you don't serioudly consider smoking at such places.
No. But none the less these are places where smoking isn't allowed.
>It's pure and simple discrimination !
That's a two way street.
That's what I meant when I said …

thekashyap 193 Practically a Posting Shark

Here is a link that gives you links for function pointer tutorials.
http://www.google.com/search?q=function+pointer+tutorial
Given you've already implemented stack, you already know that part. If you are looking for something more specific, you'll have to make the question specific. :)

thekashyap 193 Practically a Posting Shark

Just one addition, in case of passing by pointer you would be dereferencing the pointer to pointer everytime you use it. Although compilers may optimize it. A reference works as an alias.

thekashyap 193 Practically a Posting Shark

Couldn't help notice such an interesting thread.. :)..
as a smoker I also have a few things to add..

The problem is, children are more likely to smoke if their parents do.

NOT true. My granpa was the only one in my family (ALL his descendants) who smoked. In fact no one else than me even drinks (alcohol; is banned in my birth-state in India).
I believe "those who like it smoke, those who don't, don't".
Quiting it is a different matter. :)

I don't understand the reason to begin smoking.

There are many interesting reasons, apart form peer pressure. Like: Trying to stop a friend from smoking, who said "don't tell me to stop until you know what it means to stop smoking"

because it is a self provoked death... is like suicide...

Medically, it's not. All those gross pictures of mouth/throat cancer, lung x-rays and ulcers etc are actually of those who smoke 20+ cigarettes a day for more than 10-20 years. (Please don't quote an exception, I also have a few who survived inspite of smoking heavily). Most smokers (at least ones I know) smoke 5-10 a day.
(Source: My doctor friend who quit smoking)

Exactly.
It's hard, but think about what a great accomplishment that would be.

It's great alright, I mean really really great, but I doubt any non-smoker would be able to know how great. In any case I'm sure every smoker knows this, and non-smokers …

thekashyap 193 Practically a Posting Shark

Or of course you can pass it by C++ reference like:

void foo( char *& ptr)
{
   ptr = new char[255];
}

int mian()
{
   char *ptr = 0;
   foo( ptr );

   <snip>
   return 0;
}
thekashyap 193 Practically a Posting Shark

this is my program..

See now we know what you don't know.. :)
See this link to learn teh abt arrays in C++. It tells you:
- What is an array?
- How create an array ?
- How to initialize an array ?
- How to access elements of an array ?
- Finally multidimensional arrays are described if you're interested.

iamthwee commented: learn to spell 'the' properly -2
thekashyap 193 Practically a Posting Shark

I also thought on those lines, but in that case #1 should fail as well.. :)

thekashyap 193 Practically a Posting Shark

I'm not exactly sure how to implement what you mean as I'm so new, but you have put me in the right direction.

Read-up the basics of arrays, function, function parameters.. <<= That's the direction !

thekashyap 193 Practically a Posting Shark

>> I'm not asking for actual source, I just want to be pointed in the right direction
That's good to know. Understandably the code you've written would be a good indication of which direction you're going in, so one can tell you whether to take a 180 degree turn or just 10 degree.. :)
If you want "general reference/direction" I would say just search for words random and array in forums and you'll have plenty of directions to go in..

thekashyap 193 Practically a Posting Shark

Line 15: Reading from cin, read from "file".
Line 18: This would always set charsPerLine to 0. (12/100) would evaluate to 0. Make it (12.0/100.0)
Line 23-24: Not clear what are you trying to do. Remember getline() remove teh '\n' char. So you won't find that in captionText. This would crash also. Assuming that charsPerLine is 5 AND there is no space in first 5 chars of captionText. This loop will keep doing --i and would make i negative, which will result in crash. (to protect against the crash you can add one more condition i >= 0 as the first condition in the while, but I'm not sure what are you doing so can't say if it's correct to do)
Line 25: This would replace ith char, not insert '\n' as (i+1)th char.

Assuming that your file contains one caption per line; and you want to read each caption from the file, chop off the unwanted chars; and store these captions in a single std::string variable separated by '\n' you can do it like this:

while( ! EOF )
{
           read eachLine from file
                 if( eachLine.size() > allowed_caption_size )
                                output_string += chopOff( eachLine ) + '\n' ;
                 else
                                output_string += eachLine + '\n' ;
}
//PS: remove extra '\n' at the end if required

Finally: I would suggest that you use vector instead of a single string containing all captions separated by '\n'. This seems to be a perfect usecase for vector. If you use …

thekashyap 193 Practically a Posting Shark

Read-up the basics of arrays, function, function parameters.. then write a program and ask for help..

thekashyap 193 Practically a Posting Shark

I don't know C++ well enough to do this. ;)

If you don't know C++ well enough to even give it a try, you should just step back and learn the basics, give this problem a try and come back if you have some issues. Because there is no way someone is gonna teach you C++ language in one post here.

thekashyap 193 Practically a Posting Shark

Well, its true!

Yeah, I believe you, it's just tough to believe. :D

Here is the excerpt from gcc guide if you can figure something more:
3.13 Options for Linking

These options come into play when the compiler links object files into an executable output file. They are meaningless if the compiler is not doing a link step. object-file-nameA file name that does not end in a special recognized suffix is considered to name an object file or library. (Object files are distinguished from libraries by the linker according to the file contents.) If linking is done, these object files are used as input to the linker.
-c-S-EIf any of these options is used, then the linker is not run, and object file names should not be used as arguments. See Overall Options.

-llibrary-l librarySearch the library named library when linking. (The second alternative with the library as a separate argument is only for POSIX compliance and is not recommended.) It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, `foo.o -lz bar.o' searches library `z' after file foo.o but before bar.o. If bar.o refers to functions in `z', those functions may not be loaded.
The linker searches a standard list of directories for the library, which is actually a file named liblibrary.a. The linker then uses this file as if it had been specified precisely …

thekashyap 193 Practically a Posting Shark

Interesting..
1. I didn't know that -lXYZ could be interpreted by linker as libXYZ.a as well. (thought it's always seen as libXYZ.so). I checked gcc manuals (gcc 4.2.0) and seems fine.
2. Only reasons I can think of why this could be happening is:
A) There are object and library files with same name in the path.
B) May be the order has something to do with the way (and how many) symbols are resolved.

Finally it's tough to believe that this:
$gcc -o test test.c -lm -L . -lxbgi -lX11
works and this
$gcc -o test test.c -lm -L . -lX11 -lxbgi
doesn't !

thekashyap 193 Practically a Posting Shark

>> Anyone can do this in C++

Yeah !

thekashyap 193 Practically a Posting Shark

Use MS Visual C++ (get Visual Studio).. you can find lotsa online tutorials for that..

thekashyap 193 Practically a Posting Shark

Look at the call stack and see which d'tor (destructor) is being called, that should tell you where the problem is..

thekashyap 193 Practically a Posting Shark

Unfortunately a flowchart is a flowchart. It can even be made for the process of deciding which TV to buy !
Given all the basic elements remain same I donno what else you're looking for.. ?

thekashyap 193 Practically a Posting Shark

if they r the same then why 2 names r being used..

Surprised that no one mentioned that they are NOT the same and that's the reason 2 different names are used. As Aia said only rule (according to standards) is
sizeof( short ) ≤ sizeof( int ) ≤ sizeof( long ) ≤ sizeof( long long )
which means that sizeof( short ) < sizeof( int ) is also possible and is not always same.

thekashyap 193 Practically a Posting Shark

In windows if you have depends.exe you can right click on any exe file and should be able see an option called Show Dependencies.. Check it out, you'll know more abt dlls.
In Unix it's ldd command that does this.

thekashyap 193 Practically a Posting Shark

A dll is not a process.. :)
May be the following will help:
- Once you've written your C/C++ code, you will compile it and then link it. Once you do this you will have an executable file (.exe on windows)
- Your code usually be using some or the other library functions (e.g. printf/cout..).
- Given this your executable would require code that is not written by your but is available say as part of OS. Such code is normally available as a dll file (dynamically linked library).
- Now when you double click your exe and run the program, all the code has to get executed and so the OS loads your code (exe) as well as all the libraries (dll) that it depends on into memory and starts executing it from main().
- This chunk of memory is logically termed as a process.

thekashyap 193 Practically a Posting Shark

If you're looking at only flowcharts here:
http://images.google.co.in/images?q=flowchart
Of course a sequence diagram is another option:
http://images.google.co.in/images?q=sequence%20diagrams
Then you also have state-chart diagrams (although for your case I don't think they'll be applicable).
http://images.google.co.in/images?&q=statechart%20diagrams

thekashyap 193 Practically a Posting Shark

Consider following the coding practice:
When you compare a const with a non-const for equality put const on LHS instead of RHS.

E.g.

//instead of this:
if ( start == 0 )
//do this:
if ( 0 == start )
thekashyap 193 Practically a Posting Shark

AFAIK, this is not the case. When a variable is declared, a block of memory is reserved for it and thats it.

You are right. That's true AFAIK. :)
But also a static variables is always guaranteed to be initialized.
Also there is a clear difference between basic and non basic types. For a non-basic type the c'tor is always called (after memory allocation). Where as for a basic type this doesnt' seem to be true.
One thing I donno is whether allocating it statically or dynamically make a difference? Don't have a compiler handy so may be someone can check if possible. This is what I'm talking abt:

int i ;
int *j = new int ;
//printf( i & *j )
//Will both i and *j print junk values?
thekashyap 193 Practically a Posting Shark

members or base class sub-objects cannot be initialized inside the body of the constructor; they can only be assigned to. initialization is always before the body of the constructor executes.

Think that answers the question adequately.
Just to be clearer.. the difference between initialization and assignment is:
1. Initialization is done at the time of (or along with) creation of the variable. (which happens only once). If this is not done it's initialized with SOME value anyway.
2. Assignment can happen anytime.

Going by the normal C/C++ tip:
do int i = 0; instead of:

int i;
i = 0;

So when you know the value for a variable at the time of it's creation it's better to initialize it to save a li'l time, rather than letting SOME value being set in initialization and then assigning it.

Finally initialization is done in the "initialization list" of c'tor. And assignment happens inside the c'tor (or anywhere for that matter).

thekashyap 193 Practically a Posting Shark

Does this help ?

#!/bin/bash

file_with_workstations_list=/tmp/input_list.txt

while read workstation_name
do
     #do you stuff with workstation_name
     echo "Read workstation name: " $workstation_name
done < $file_with_workstations_list
thekashyap 193 Practically a Posting Shark

Can't find the decl of IDI_APPLICATION.

thekashyap 193 Practically a Posting Shark

Can you post declaration/definition of IDI_APPLICATION ?

thekashyap 193 Practically a Posting Shark

Just wondering that after #including vector/list etc, why are you using C-style array for this? Use C++ array (i.e. vector) instead, life is so much more easy.

#include <iostream>
#include <list>
#include <iterator>
#include <vector>

using namespace std;

class humanPlayer
{
public:                                                             
  humanPlayer(string thePlayersName, unsigned int thePlayersTurnNum); 
  ~humanPlayer(){};  

  void addToList(unsigned int countryToAdd) {countriesOwned.push_back(countryToAdd);} 
  void showList();
  void removeFromList(unsigned int countryToRemove) {countriesOwned.remove(countryToRemove);}
  void checkIfInList(unsigned int countryToCheck);

  string getPlayerName() {return playerName;}  
  int getPlayerTurnNum() {return playerTurnNum;}
  void setPlayerTurnNum(unsigned int newPlayerTurnNum);

private:
  list<int> countriesOwned;
  string playerName;
  unsigned int playerTurnNum;
};
humanPlayer::humanPlayer(string thePlayersName, unsigned int thePlayersTurnNum)
  {
  playerName = thePlayersName;
  playerTurnNum = thePlayersTurnNum;
  }

void humanPlayer::checkIfInList(unsigned int countryToCheck)
  {
  if(find(countriesOwned.begin(), countriesOwned.end(), countryToCheck) != countriesOwned.end())
       {
       cout << countryToCheck << " is in the list.\n";
       }
  else
       {
       cout << countryToCheck << " is NOT in the list.\n";
       }
  }

void humanPlayer::showList()
  {
  copy(countriesOwned.begin(),countriesOwned.end(),ostream_iterator<int>(cout,", "));
  cout << endl;
  } 

void humanPlayer::setPlayerTurnNum(unsigned int newPlayerTurnNum)
  {
  playerTurnNum = newPlayerTurnNum;
  }
 
void getName(vector<humanPlayer>& jailHouse);
void print_it(const vector<humanPlayer>& jailHouse) ;

//unsigned int numOfPlayers; //not needed, use jailHouse.size() instead.
 
int main()
     {
     vector<humanPlayer> jailHouse ;
     getName(jailHouse);
     print_it(jailHouse) ;
 
     system("PAUSE");
     }  
 
void getName(vector<humanPlayer>& jailHouse)
     {
     cout << "How many players will there be? ";
     cin >> numOfPlayers;
     cout << endl;
 
     for(unsigned int i=0 ; i<numOfPlayers ; i++)
          {
          char name[256];
          cin.ignore(255,'\n');
          cout << "What is player " << (i+1) << "'s name? ";
          cin.get(name,256);
 
          jailHouse.push_back( new humanPlayer(name, (i+1)) );
          }     
 
     }

void print_it(const vector<humanPlayer>& jailHouse)
{
    for( int i = 0; i < jailHouse.size(); i++ )
        cout << i << " = …
thekashyap 193 Practically a Posting Shark

you can unpack both libraries and repack them using ar.

How do you unpack? I know that my compiler doesn't allow archiving archive files.

thekashyap 193 Practically a Posting Shark

Heard of Unix aliases ?!
If you don't wanna do that, you can also say x="that whole command"
and then
$x

thekashyap 193 Practically a Posting Shark

Or in case you've by mistake posted this in C instead of C++ the prototype of interest would be

void foo(int& prm1, int& prm2, int& prm3);
thekashyap 193 Practically a Posting Shark

Surprising Salem didn't comment on this.. :)

[PS: those wondering why, see his icon/avatar]

thekashyap 193 Practically a Posting Shark

>
Better yet, instead of using the [] as vector accessors, use std::iterator.

Probably to learn iterators. But otherwise vector being the C++ array one should use the subscript operator for accessing rather than iterator. It's faster.

thekashyap 193 Practically a Posting Shark

Can you just tell me what I should put? I would probably learn it quicker that way anyhow.

If you had a look at the link this is what you would've seen:
-------------------------------------
Comparing with epsilon – absolute error

Since floating point calculations involve a bit of uncertainty we can try to allow for this by seeing if two numbers are ‘close’ to each other. If you decide – based on error analysis, testing, or a wild guess – that the result should always be within 0.00001 of the expected result then you can change your comparison to this:
if (fabs(result - expectedResult) < 0.00001)
The maximum error value is typically called epsilon.
-------------------------------------
I think that tells you exactly what to do.

It is late, and the assignment is due early.

It's always late and assignments are always due early :)

thekashyap 193 Practically a Posting Shark

that's why I have this sucker at the end: array++;

Sorry.. didn't see that one.. :)

Well, if this is an assignment I think the prof's idea is to teach floating point number comparison. See this thread I had posted. It has some description of the problems and has this link that describes in detail solutions and other problems.
After you've read it you'll understand that your problem stmt says you should use this method: "Comparing with epsilon – absolute error"

thekashyap 193 Practically a Posting Shark

You could post the "idea" as well.. Ppl will tell you if something is wrong.
One I can tell you is:

if (*array > ave)
else if (*array < ave)

Although this is inside the loop it'll always test only the first element of the array. To access other elements in the array you should use the subscript operator (operator []).

thekashyap 193 Practically a Posting Shark

agreed that kind of messy stuff isn't needed when using portable functions like clock(). I think I was referring to using non-portable code such as getrusage(). And there are, of course, hundreds of other non-portable examples.

Yup, for non-portable things it would be needed. That's why I mentioned "this particular case". :)

thekashyap 193 Practically a Posting Shark

will probably have to program for both by using preprocessor directives for each compiler

#if defined _WINDOWS
// do MS-Wndows specific code here
#else
// do *nix specific code here
#endif

Given that the code posted by me/Vijayan works both on windows and unix #ifdefs won't be needed in this particular case.

Ancient Dragon commented: good point +14
thekashyap 193 Practically a Posting Shark

Thanks everyone for all your posts. Will try different solutions and see what works. Thing is, does the fact that noone has mentioned getrusage() mean that noone here uses it?

In short no, AFAIK ppl don't use getrusage() for this purpose. Because you can as well use time/timex for this purpose.
Difference between what others have suggested here and getrusage() is that getrusage() gives you something very similar to what time (or timex) commands (on unix) will give you, viz overall CPU time taken. Whereas other techniques will give you time for any smaller part of your program. More like white-box and black-box.

thekashyap 193 Practically a Posting Shark

And truth be told I really have no clue what to do except

boolean[] deck = new boolean[52];

can anyone give me any insight..? I've no idea where to place it or what else to do.

Guess you wanna know how to use an array. Here is a crash course:
1. Declare and define an array:

type var_name[] = new type[array_size] ;

Where type could be a basic type (like int, boolean...) or a user defined type (like Poker)
2. Access a member of array which is located at index/position N:
Use the subscript operator (i.e. "[]" ) like this var_name[N].

System.out.println( "Nth element = " + String.valueOf(var_name[N]) ) ;
/*PS: valueOf() is overloaded for basic types only, won't work for user-defined types*/

To assign a value:

var_name[N] = new type() ;

3. Loop thru an array: array_variable_name.length gives you the length of an array.

for( int i = 0; i < var_name.length; i++ )
     System.out.println( String.valueOf( var_name[i] ) ) ;

Here is a full example:

public class test {
    public static void main( String[] args ) {
        //declare and define
        boolean arr[] = new boolean[10] ;
        //init
        for( int i = 0; i < arr.length; i++ )
            arr[i] = false ;

        //access an element
        arr[(int) (Math.random() * 10)] = true ;

        //print the contents
        for( int i = 0; i < arr.length; i++ )
            System.out.println( String.valueOf( arr[i] ) ) ;
    }
}
thekashyap 193 Practically a Posting Shark

First I assume your question is how to find out the performance/time of your function. In this case I really donno how you can use Sleep ?!
As I use timing quite frequently I have the following code (similar to Vijyan's) I use to make it easy to use.

#include <ctime>
#include <iostream>

using namespace std ;

#define CREATE_CLOCK() clock_t ____start, ____diff = 0 ;
#define START_CLOCK() ____start = clock() ;
#define REPORT_CLOCK_DIFF() ____diff = clock() - ____start ; \
std::cout << std::endl << "CLOCKS_PER_SEC = " << CLOCKS_PER_SEC << std::endl \
<< "difference = " << ____diff << ", diff/CLOCKS_PER_SEC = " << ____diff/CLOCKS_PER_SEC << std::endl ;

int main()
{
        CREATE_CLOCK()

        START_CLOCK()
        /*do your stuff*/
        REPORT_CLOCK_DIFF()

        START_CLOCK()
        /*do your stuff*/
        REPORT_CLOCK_DIFF()

        return 0 ;
}

Output is like this:
---------------------------------------------------
On Solaris 10 with Sun WorkShop 6 update 2 C++
CLOCKS_PER_SEC = 1000000
difference = 0, diff/CLOCKS_PER_SEC = 0

CLOCKS_PER_SEC = 1000000
difference = 0, diff/CLOCKS_PER_SEC = 0
---------------------------------------------------
On Windows 2000 with VS 6.0:
CLOCKS_PER_SEC = 1000
difference = 0, diff/CLOCKS_PER_SEC = 0

CLOCKS_PER_SEC = 1000
difference = 0, diff/CLOCKS_PER_SEC = 0
Press any key to continue
---------------------------------------------------
As you can see CLOCKS_PER_SEC is different for different compilers (or may be it's due to hardware, not sure).
diff/CLOCKS_PER_SEC gives you the time taken for /*do your stuff*/ in seconds.

>> My second question is more general (for now), does anyone know why …