thekashyap 193 Practically a Posting Shark

Although your confidence in abilities of us at daniweb is overwhelming, we have not yet mastered the art of telepathy or remote desktop viewing. So we are unable to see what the errors are.

Read this . It tells you which lib, bgi you need and so on.
Also note graphics.h is too old now. If you're starting off with learning, use something newer.

thekashyap 193 Practically a Posting Shark

May be there is an easier way, but here is what I can think of..

total_params=`echo $* | sed 's/ */\n/g' | sort | sed '/^$/d' | wc -l`
unique_params=`echo $* | sed 's/ */\n/g' | sort -u | sed '/^$/d' | wc -l`
[ $total_params -ne $unique_params ] && echo "repeat" || echo "no repeat"

PS: There is a bit of catch with sort as it adds some newline chars by itself, that's why the /^$/d at end.

thekashyap 193 Practically a Posting Shark

I am really interested in your process_TC_config_file() script you posted but I don't yet fully understand it, but am working on it. Is that a function? sub-routine? something else?

Yes, it's a function.
Just to make code readable. Hope you noticed that the function is called from line number 56.

I think it was also posted by you.

Nope, I would never show anyone how to use arrays in shell scripting. I hate them for their god-awful-cryptic-unreadable-confusing-crappy syntax.

APPLICATION=${lines[0]}
REMOTEHOST=${lines[1]}
WEBDATA=${lines[2]}

I'm not the most user-friendly guy, but this is stretching limits of user-unfriendliness. Expecting user to specify specific parameter WITHOUT a corresponding key name on a specific line number. Not good.


Technically though all are an option pick whatever sails your boat. I, like any self-respecting poster, would of course root for my way. :)

HTH = hth?

HTH = hth

thekashyap 193 Practically a Posting Shark

Well, what you ask is a very basic question, so a bit difficult to answer in short. I'll try:
ClassLoader(s) are used by JVM to load classes as and when they're used (one of the 5) by the code being executed.
Given a fully qualified class name, what it does is:
- locate the class in the classpath.
- reads the .class file and load it into JVM memory.
- initialize (optionally as we discussed)
- it also takes care of security etc, but not relevant to current discussion.
Usually you never bother abt them, as the default class loader impl packaged with the JRE is good enough. It does what you need transparently.

Most of the JVM code uses ClassLoader. E.g. every time you access a class by doing a "new XXX()" JVM would call ClassLoader to load XXX if it's not already loaded. Same goes for other 5 options. Or in your words: "something to happen with the class or it static field or methods" ==> To make any of this to happen, JVM has to call ClassLoader if the class in question is not already loaded.

I suggest you put a break point in teh forName() method in Eclipse and debug a hello world program step-by-step. You'll see what all it does.

Hope it's clearer now.

warlord902 commented: Thanks for explaining +2
thekashyap 193 Practically a Posting Shark

There are 2 simple options:
1. If the number of params are not too many just pass them on command line:

#/bin/bash
APPLICATION=$1
LOCALHOST=`hostname -s`
REMOTEHOST=$2
WEBDATA=$3
SQLUSER=$4
SQLPASS=$5
SQLDB=$6

# ---------------------------------------------
#run like this:
backup.sh appName remotehost webdataLocation usr pswd db

You name make them named params using the getopt. Google for more examples.

2. Use the file as you mentioned. Usually I would go with the property file syntax.
key=value
In this case you can parse the file like this. An except from one of my scripts:

#!/bin/bash
#
# Sets internal variables based on <config file> contents.
# $1 - <config file>
# returns nothing, sets all variables.
#
process_TC_config_file() {
	_logecho "Entering _process_TC_config_file(): \$* = $*"
	_logecho "TC_CONFIG_FILE=$TC_CONFIG_FILE"
	local NEW_INPUT_FILE=$TC_DIR/new_config
	cp $1 $NEW_INPUT_FILE

	# remove leading spaces/tabs and comments
	sed -i '/^$/d;s/^[ \t]+//g;/^#/d' $NEW_INPUT_FILE
	# work around for "read". It returns non-zero for last line in file.
	# So if the last line contains valid input it will be lost.
	echo "" >> $NEW_INPUT_FILE
	
	while read one_line
	do
		if [ ! -z "$(echo $one_line | grep ^ADAPTATIONS)" ]; then
			ADAP_LIST=`echo $one_line | sed 's/ADAPTATIONS=//'`
		elif [ ! -z "$(echo $one_line | grep ^NUMBER_OF_HOURS_OF_DATA_LOADING)" ]; then
			NUMBER_OF_HOURS_OF_DATA_LOADING=`echo $one_line | sed 's/NUMBER_OF_HOURS_OF_DATA_LOADING=//'`
		elif [ ! -z "$(echo $one_line | grep ^ORACLE_MEM_SET_SIZE_PERCENT)" ]; then
			ORACLE_MEM_SET_SIZE_PERCENT=`echo $one_line | sed 's/ORACLE_MEM_SET_SIZE_PERCENT=//'`
		elif [ ! -z "$(echo $one_line | grep ^DB_ARCHIVE_LOGGING_DIR)" ]; then
			DB_ARCHIVE_LOGGING_DIR=`echo $one_line | sed 's/DB_ARCHIVE_LOGGING_DIR=//'`
		elif [ ! -z …
thekashyap 193 Practically a Posting Shark

Solution: Use "^...$" kinda pattern.

So I think I figured out what's wrong with your pattern.

Problem is that given the way you've grouped your pattern, matcher would try to match it with strings starting and ending with each char of your input string.
This blows up the number of combinations to match with almost exponentially. As you can see below the time taken goes down by almost half as I remove one char from the input string.

What I mean by starting and ending with each char is that if your input string is say "ab cd" then, matcher would have to check all following combinations against the pattern:

- 'ab cd'

- 'a'
- 'ab'
- 'ab '
- 'ab c'

- 'b cd'
- ' cd'
- 'cd'
- 'd'

- 'b c'
- 'b '
- 'b'

- ' cd'
- ' c'
- ' '
- 'cd'
- 'c'

And as number of chars increase number of such combinations go exponentially higher.

[B]root@forssa $[/B] java com.kash.TestMain "abcdefghikklmnopqrstuvwxyz1234567890"

Test string --> "abcdefghikklmnopqrstuvwxyz1234567890"

pattern = "^[a-zA-Z'-]*[ ]*$"
Match time:     206451 nanosecs

pattern = "([a-zA-Z'-]*[ ]*)*"
Match time:     17731438213 nanosecs

[B]root@forssa $[/B] java com.kash.TestMain "bcdefghikklmnopqrstuvwxyz1234567890"

Test string --> "bcdefghikklmnopqrstuvwxyz1234567890"

pattern = "^[a-zA-Z'-]*[ ]*$"
Match time:     191923 nanosecs

pattern = "([a-zA-Z'-]*[ ]*)*"
Match time:     8909746071 nanosecs

[B]root@forssa $[/B] java com.kash.TestMain "cdefghikklmnopqrstuvwxyz1234567890"

Test string --> "cdefghikklmnopqrstuvwxyz1234567890"

pattern …
mKorbel commented: JProfiler +8
thekashyap 193 Practically a Posting Shark

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects.

A brief on problem:
Lets take example problem for simplicity:
- I have a GSM network with a cell in it.
- Cell's coverage area is divided into a pixel grid with dimensions 2000x2000.
- at each pixel the signal strength is measured.
Requirement is to find out the % of pixels in a cell that have below par signal strength.

Solution 1 using the good old C:
In C, memory is dealt in raw. You want memory, allocate the number of bytes you want. No guarantees are give regarding the contents of that memory (using malloc()). At best you can initialize the whole block of memory you allocated with "zeros" (calloc() or memset()), but not to a value specific to your application (not unless you REALLY go deep into how your specific compiler creates the memory map for your data).

// Solution 1
#include <stdio.h>
#include <stdlib.h>
#define GRID_WIDTH 200
#define GRID_HEIGHT 200
#define MIN_SIGNAL_STRENGTH 3

typedef struct pixelStruct {
    int _x;
    int _y;
    int _signal_strength;
} t_pixel;

void print_pixel( const char* msg, const t_pixel* ptr ) {
    cout << msg << endl << "\tptr = 0x" << hex << ptr << ", x = " << ptr->_x << ", y = " << ptr->_y << ", signal_strength = " << ptr->_signal_strength << endl; …
Narue commented: Nice. +17
mike_2000_17 commented: Nice post... but... +11
thekashyap 193 Practically a Posting Shark

Sorry my bad. I did not read "from remote windows machine on linux?"
Well, I've never done this. In fact I've never even connected from a windows to windows from command line.
I assume telnet works?
have you tried:

telnet <machine> <<EO_MY_INPUT >> output_of_telnet_session.txt
<password>
date /t (or whichever is the command to get date/time)
exit
EO_MY_INPUT

You should have the output in output_of_telnet_session.txt, which you can parse using std linux stuff, grep, sed, awk,...
If you have password-less authentication setup, skip the password on line 2.

thekashyap 193 Practically a Posting Shark

So feel free to design it.. ! :)

thekashyap 193 Practically a Posting Shark

Syntax of your xml is wrong. You can't have the outermost tag twice in a file. So modified it a bit and assume that's what you want.

<xml>
  <entry>
    <name>aaaa</name>
    <surname>bbbb</surname>
  </entry>
  <entry>
    <name>eeee</name>
    <surname>ffff</surname>
  </entry>
</xml>

Given that you already have code ( {print /uid=/?$4:(/^telephoneN/)?$2:$3} ) that can print line 3, 4 & 7, 8. Just add the xml tag in front and back appropriately. For opening and closing of each ( <entry> ) can also be done in this line itself.
For teh opening and closing tags ( <xml> ) of the file itself use BEGIN{} and END{} of awk. These are like c'tor / d'tor in awk, get executed before and after parsing of 1.txt.

If there are cases where the input file isn't consistent (name / surname is missing), you can use if/else/...

thekashyap 193 Practically a Posting Shark

Actually you're pretty far from linking trouble. You have major compilation issues.
Few things you need to fix and remember:
1. DO NOT USE things like "Student", "iostream", "Name", "Date" as include guards. Make YOUR include guards unique. Qualify these names with your street address if needed. E.g. #ifndef student_Casper3912_myCountry_myCity_myStreet.
==> Better use #pragma once
2. Include guards are placed in .h file NOT in .cpp files (those days are gone!)
3. Be careful in what you include, following 3 are not the same:

#include <string>
#include <string.h>
#include <String.h>

4. Never #include .cpp files (main.cpp)
5. Don't use this. unless you know what you're doing.
6. A function call must have () at the end. :) E.g. From Student.cpp

this.GetSName.GetFirstName()
// should be:
GetSName().GetFirstName()

7. You need to add using std::cout, std::string etc wherever required.


I've fixed all errors in Student class and attached. See that example and fix other places.

thekashyap 193 Practically a Posting Shark
#include<stdlib.h>
#include<stdio.h>
#include<string.h>

typedef struct linked_list_elem {
    char *val;
    struct linked_list_elem* next;
} t_linked_list_elem;

t_linked_list_elem* head = NULL;
t_linked_list_elem* tail = NULL;

// Finds given string in given linked list.
// returns: the t_linked_list_elem matching the string if found,
//          NULL otherwise.
t_linked_list_elem* findItem (const char* string);

// If string already existed in the list, returns the existing item.
// Else adds given string at the end of list and returns the added item.
t_linked_list_elem* addItem (const char* string);

void printList ();

int main() {
    FILE* tFile;
    tFile = fopen ("D:\\Temp\\myFile.txt", "r"); // assume the file exists and has data
    char buf[35];
    //curr= head;
    while (!feof (tFile)) {
        fscanf (tFile, "%s", buf);
        //printf ("BEFORE ADDING: %s", buf);
        //printList ();
        addItem (buf);
        //printf ("AFTER ADDING: %s", buf);
        //printList ();
    }

    printf ("\n\nFinal List\n");
    printList ();

    return 0;
}

t_linked_list_elem* findItem (const char* string) {
    if (head != NULL) {
        t_linked_list_elem* curr = head;
        do {
            if (0 == strcmp (string, curr->val))
                return curr;
            else
                curr = curr->next;

        } while (curr != NULL);
    }
    return NULL;
}

t_linked_list_elem* addItem (const char* string) {
    t_linked_list_elem* existing = findItem (string);
    if (existing != NULL) {
        printf("Trying to add an item (%s) that already existed. Would be ignored.\n", string);
        return existing;
    }

    t_linked_list_elem* newItem = (t_linked_list_elem*) malloc (sizeof (t_linked_list_elem));
    newItem->val = (char*) malloc (strlen (string) * sizeof (char) + 1);
    strcpy (newItem->val, string);
    newItem->next = NULL;

    if (NULL == head) {
        head = newItem;
        tail = head;
    } else {
        tail->next = newItem;
        tail …
thekashyap 193 Practically a Posting Shark

@thekashyap: I was just wondering in regard to your comment "Also I suggest you read up a bit on what c'tors are called by compiler at what point. Your code isn't optimal.":
Are you suggesting that I don't need to include all the constructors that I am including? In actual fact I started out just with my main one, but then I added the default one while I was trying to fix the problem, and then added a copy constructor as well in a similar act of desperation hehe.

What I meant is that passing / declaring everything by value is not optimal. It leads to creation of unnecessary objects.
E.g. if you change

Display::Display(Machine v) { // pass by value
to
Display::Display(Machine& v) { // pass by reference

Then you can see that c'tor of Machine is called only 2 times (instead of 3 times in pass by value).

main -- creating Machine
inside Machine(vector<Cigarette>) id = 1
main -- m.id = 1
main -- creating Display
inside Machine() id = 2
inside Display(Machine v)
inside operator =(const Machine& rhs) - this.id = 2, rhs.id = 1
Exiting -- Display(Machine v)
main -- exiting main() i = 2

Same can be applied to Machine (vector<Cigarette>& c) . This would avoid creation of a copy the whole vector before the call to Machine() is made.

Extending the same to member variable.

change
    vector<Cigarette> cigs;
to
    vector<Cigarette>& cigs;

This would avoid make cigs a reference …

jonsca commented: Nice job on this thread +8
thekashyap 193 Practically a Posting Shark

Did you read up anything on how to use sockets in Java?
First 2 results seem good enough..

thekashyap 193 Practically a Posting Shark

So I'm using gcc (CodeBlocks).
I do not get the error you're talking abt with the code you posted (+I modified a bit).
Here is the output my code generates. Perhaps it gives you an idea of what's happening.
I've added comments to explain why what's called.
HTH.

main -- creating Machine
inside Machine(vector<Cigarette>) id = 1  [B]<-- main().Machine m(v);[/B]
main -- m.id = 1
main -- creating Display
inside Machine(const Machine&) id = 2 [B]<-- Display(Machine v), as v is passed by value,
                                          a copy is created using copy co'tor.[/B]
inside Machine() id = 3[B] <-- Display.h - Machine vend; (the member variable
                            declared by size is created)[/B]
inside Display(Machine v) [B]<-- main().Display d(m);[/B]
inside operator =(const Machine& rhs) - this.id = 3, rhs.id = 2 [B]<-- Display:: Display(Machine v).vend=v;[/B]
Exiting -- Display(Machine v)
main -- exiting main() i = 3

Process returned 0 (0x0)   execution time : 0.046 s
Press any key to continue.

Code that generated this is attached.

thekashyap 193 Practically a Posting Shark

Can you send the command lines and the outputs with error?
Also given that there is nothing "not-extern" in the headers you posted, the problem (repeated definition of...) can't be due to these as extern doesn't define anything it only declares.
Hope you do know the use of extern.

--edit--
Guess at the cause would be:
- There are multiple object files (.o file) that export this symbol.
- This in turn would be usually because you have #included the header that actually defines this symbol in two diff .cxx files
- compiled them to create two diff .o files and then
- trying to link them (both .o) together.

If there are too many source files I recommend use of nm -C -g on all .o files.

thekashyap 193 Practically a Posting Shark
package com.kash;

import java.util.Scanner;
import java.util.StringTokenizer;

public class TestMain {
	public static void main(String[] args) {
		int pos = 0;
		String input;
		Scanner s = new Scanner(System.in);

		int count = 0;

		while (true) {
			System.out.print("Enter a sentence: ");
			input = s.nextLine();
			System.out.println("input = \"" + input + '"');

			StringTokenizer str = new StringTokenizer(input);

			if (!input.equals("")) {
				while (str.hasMoreTokens()) {
					count++;
					String word = str.nextToken();
					System.out.println(pos + " " + word);
					pos++;
				}
			} else
				break;
		}
	}
}
CorruptionInc commented: Thanks a lot! +0
thekashyap 193 Practically a Posting Shark

Before Tom Cruise, Chuck Norris was approached by makers of "Mission Impossible". But he found the movie title insulting.

thekashyap 193 Practically a Posting Shark

Here is the pseudo-code:

// Create an array of char*(s)
// You might be forced to use a custom struct (see comments
// below) if you want to control the memory usage.
while (fscanf(myfile, "%s", str) != EOF) {
// Extract each word (find index of next white space char
// and then substring) out of str and add it into array.
}
// call the function that can sort this array (using bubble sort).
// loop over the array
//     count++ as long as next matches previous
//     if doesn't match print count

See these for hints on arrays.
http://cboard.cprogramming.com/c-programming/104527-using-realloc-dynamically-growing-array.html
http://stackoverflow.com/questions/3536153/c-dynamically-growing-array

thekashyap 193 Practically a Posting Shark

At least read the output printed by your script ! woooee has been nice enough to add traces to your script, don't expect s/he isn't going to DO IT for you.
HINT: How many times do you expect " print "comparing", s[index], s[-1-index], "for index", index " to be executed and check how many time is it actually executed.

thekashyap 193 Practically a Posting Shark

As I said, tree is the best thing I can think of.
Somethihg like this (See attached):
- One digit per node.
- Only a leaf node corresponds to a match. So contains the country name.
While matching you just have to keep going (matching digit by digit) until you reach a leaf node (node without children), just pick up the country name from it and return.

This should be most performant unless Narue says otherwise, think she's the guru of data structures around here.. :)

thekashyap 193 Practically a Posting Shark

An English teacher is teaching kids new words. As an exercise she gives an assignment to all kids to learn a new word from the dictionary and use it in a sentence.
Next day she asks Harry "So Harry what is your word?"
Harry says: "Pregnant" and it means "carrying a child."
Teacher "Use it in a sentence"
Harry "A fireman went inside a burning house and came out pregnant."

Aia commented: A hero that fireman is. +6
thekashyap 193 Practically a Posting Shark

Some more of exams..

* A vibration is a motion that cannot make up its mind which way it
wants to go.

* Many dead animals in the past changed to fossils while others preferred to be oil.

* I am not sure how clouds get formed. But the clouds know how to do it, and that is the important thing.

* Thunder is a rich source of loudness.

* Water is composed of two gins, Oxygin and Hydrogin. Oxygin is pure gin. Hydrogin is gin and water.

* "To keep milk from turning sour: keep it in the cow."

One day, leaning on the bar, Jack says to Mike "My elbow hurts like hell. I suppose I'd better see a Doctor!"

Listen, don't waste your time down at the surgery," Mike replies.
There's a new diagnostic computer at Tesco Pharmacy. Just give it a urine sample and the computer will tell you what's wrong, and what to do about it. It takes ten seconds and only costs five quid.....a lot quicker and better than a doctor and you get Club card points".

Jack collects a urine sample in a small jar and takes it to Tesco. He deposits five pounds and the computer lights up and asks for the urine sample. He pours the sample into the slot and waits. Ten seconds later, the computer ejects a printout:

You have tennis elbow. Soak your arm in warm water and avoid heavy activity. It will improve in …

~s.o.s~ commented: I don't know where you come up with these jokes, but you know it and thats the important thing. :) +24
thekashyap 193 Practically a Posting Shark

Hey, is the Java VM written in C++ ?

Yeah, I first noticed that "java" executable is written in C/C++ when I had some hotspot error and it wrote down a core file, whose pstack showed calls from main()->createVM()... So it's C at least if not C++.
You can execute "file java" on unix to see this. Also if you have some tools to list out names in a file like nm, or c++filt...

Anyway, that is no scale to say that C/C++ is better than Java.

For the original question, I would say that decide the industry (telecome, services, product-based, web-services...) you wanna go to, and pick based on that. If you donno which industry then just leave C/C++ and Core Java all 3 of them, shouldn't take you long to learn the languages. It will surely take some time to actually be good at programming in ANY 3 of them. Coz write code and write good are different things. :)
Abt java, given that apart from core java you have a 100 other things you can learn e.g. J2EE itself is a Pandora's box.

A personal note: every time I have interviewed a candidate for a job in my projects, I have looked for language/theoretical knowledge and good attitude in freshers (just outa collage) and programming knowledge in candidates with prior experience.

iamthwee commented: Please refrain from using abbreviations or acronyms in your posts. Write fully coherent, properly structured sentences or suffer my wrath. Mu-hah- ha. +11
Rashakil Fol commented: Don't worry about his wrath; I'll counterbalance it. +9
thekashyap 193 Practically a Posting Shark

I needed to get links to some good Java, J2EE tutorials and was surprised that daniweb::Java didn't have a thread on that..

Of course it's easy enough having Sun provide tutorials on most things, there might be some covering specific topics in better ways.
Anyway here are the links I have found so far on java.sun.com, please post if you find some other tried and tested ones:

Core Java/Basics

  • Getting Started — An introduction to Java technology and lessons on installing Java development software and using it to create a simple program.
  • Learning the Java Language — Lessons describing the essential concepts and features of the Java Programming Language.
  • Essential Java Classes — Lessons on exceptions, basic input/output, concurrency, regular expressions, and the platform environment.
  • Collections — Lessons on using and extending the Java Collections Framework.
  • Swing — An introduction to the Swing GUI toolkit, with an overview of features and a visual catalog of components. See below for a more comprehensive tutorial on Swing.
  • Deployment — How to package applications and applets using JAR files, and deploy them using Java Web Start and Java Plug-in.

Specialized Trails and Lessons

peter_budo commented: Nice job with collecting all this links +7
thekashyap 193 Practically a Posting Shark

See this thread.. it should answer all your questions and give you enough examples..

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

If you know that the conversion works, it doesn't matter, right?

Now that's perfect question to be answered with someone's signature (I really searched for it and couldn't find) which goes something like:
"Although it might be possible to collect the twigs using your nose, it doesn't necessarily mean it's the best way."
I'm assuming you didn't see the problem.
------------------------------------------
Calling free_function() with pb. => Remember pb points to object of type base, which does not implement a function named special_function().

Inside base::some_function()
dynamic_cast returned NULL. pb was NOT pointing to an obj of type derived. => dynamic_cast knows that pb can not and must not be converted to derived*, so it returns NULL.

Doing C-style casting
Inside derived::special_function() => Even though this object does not have this function a call to it is successful. This is only bad-luck.
------------------------------------------
Now if you still doesn't see the problem, let me give you another one:

#include <iostream>

using namespace std;

enum ActionEnum { GET_LAN_STATUS,
        SHUTDOWN_LAN
     } ;

class employee
{
public:
    employee(const string nameStr):name(nameStr) {}
    virtual ~employee() {cout << "Inside ~employee()" << endl ;}
    virtual void get_status_of_office_LAN() {cout << "get_status_of_office_LAN() by: " << name.c_str() << endl ;}
    string getname() { return name ; }
protected:
    string name ;
};

class administrator : public employee
{
public:
    administrator(const string nameStr):employee(nameStr) {}
    ~administrator() {cout << "Inside ~administrator()" << endl ;}
    void get_status_of_office_LAN() {cout << "get_status_of_office_LAN() by: " << name.c_str() << endl ;}
    void shutdown_office_LAN() …
John A commented: Good job. +13
thekashyap 193 Practically a Posting Shark

>> int fildes = open("/dev/hda", O_RDWR);
Seems like you're trying to access a special file (device)
I donno abt those. Check is the man page says anything abt it.
There are at least 2 attributes that indicate this:
1. dev_t st_rdev; /* ID of device */
2. char st_fstype[_ST_FSTYPSZ]; /* Null-terminated type of filesystem */
But they only seem to indicate that it's a special file.

thekashyap 193 Practically a Posting Shark

Looks like local_jlist is a function local variable (inpublic Prod_applet()).. and not in the scope where you're using it (line 226).. make it a member variable.. it should work..

peter_budo commented: Quick spoted error +6
thekashyap 193 Practically a Posting Shark

It's pretty simple first create a binary tree, then read the input and insert each element in appropriate place in teh tree, then read it back in postfix notation.
Let us know once you're done with the code if you need more help.

Narue commented: Just that simple, huh? ;) +13
iamthwee commented: learn 2 spell the properly. -2
Aia commented: ++thekashyap; +2
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

But it took me an entire half-day to track it down, since the segfault occurred down the line from where the overflow actually was

Tell me abt it.. :)
Guess everyone faces this some time or the other while they learn programming..
That's teh reason I used words "lucky/unlucky".. may be after a few years your hand will get used to not making ArrayOutOfBound errors..

~s.o.s~ commented: Tell me one programmer who hasn't faced that error ;-) ~s.o.s~ +17
thekashyap 193 Practically a Posting Shark

You don't need a array of 5 ints to store a 5 digit integer. Change the struct to:

struct person
{
        long phone number;
         string name;
         string address;
         int zip;
}

Abt reading from file and storing in struct. Post the code you write to do this and we'll help with any specific problem. See code snippets to get started with file reading and parsing.

pulse0 commented: Great helper!!! +1
thekashyap 193 Practically a Posting Shark

You can't take a 2D array as a function argument with both diamentions of variable length (it's allowed for single diamention but not for more than one !)
i.e.

void my_function1( int arr_1D[] ) {/*...*/} //This is allowed
void my_function2( int arr_2D[][] ) {/*...*/} //This is NOT allowed

make it: void sum(int, int[igg][jgg]); and it should work

Aia commented: Great advice -Aia +1
thekashyap 193 Practically a Posting Shark

A word on unresolved symbol:
This is the oppisite of "multiple definitions". In this case you have put extern declaration in some file, (so compiler is happy and leaves the work of finding it's definition to liner). But because none of the translation units you

May the concept of symbols and linkage and scope isn't clear to you.
- Say you have a.h/a.c b.h/b.c and main.c
- Say main.c #includes a.h and b.h and uses the functions declared there.
- You need to have a variable "int global_var ;" that you need to use in all 3 places (main, a, b).

So the question is where should you put int global_var ; ?
- You are going to compile 3 files a/b/main.c and create a/b/main.o. These 3 are your translation units (or program units as Ancient Dragon refer to it)
- You should define (for a non-static basic type independent variable declaration is also definition) only ONE int global_var; because you want all 3 of them to use the same variable not a different one.
- So what you do is, define it in ONE place and put some special statement in other two places that promises compiler that this variable will be defined at link time, so ignore for the time being.
- This special statement consists of keyword extern. When you prefix some declaration with this word it tells compiler that it is NOT defined in this translation …

John A commented: A little rep for ya --joeprogrammer +8
thekashyap 193 Practically a Posting Shark

you are right -- I didn't read the expected outcome, which is impossible. There is no solution that will give that outcome.

What abt GOTO LABEL?

if ( true )
{
     cout << "Hi" << endl ;
     goto ELSE_PART ;
}
else
{
ELSE_PART:
     cout << " There" << endl ;
}

of course that's cheating but then teh question is not fair.. :)

thekashyap 193 Practically a Posting Shark

It's hard to explain in precisely the given code. I need to know types and values of AFE_REG_FLAG_CDR and AFE_REG_FLAG_MSR. Also what're all these flags used for?

In general may be some example will help:
Say you have a class that reprents a file. An object of this would have many states. Say our object has following:
1. good - when this flag is 1 it means the object is good for usage.
2. eof - when this flag is 1 it means the file pointer is at the end of file.
3. bof - when this flag is 1 it means the file pointer is at the begenning of file.
4. error - when this flag is 1 it means that last operation performed (read/write/seek...) on file failed.
One of implementing this would be to use 4 booleans. Another is to use a single char variable (whose size say is 1 byte = 8-bits) and use 4 bits to represent these 4 flags (other 4 are ignored).
Say like this:

8    7    6    5    4    3    2    1
                    ^    ^    ^    ^
|<-- ignored-->|  good  err  eof  bof

Say in our class we provide 8 functions:
get_good(),set_good()
get_bad(),set_bad()
get_eof(),set_eof()
get_bof(),set_bof()
to get/set the values of these 4 flags.
Now if we had booleans: our function would look like this:

bool my_class::get_good() { return m_good_bool ; }
bool my_class::set_good(bool new_val) { m_good_bool = new_val;}
~s.o.s~ commented: Rep from ~s.o.s~, I like your way of teaching... :D +15
jaepi commented: nice one +1
thekashyap 193 Practically a Posting Shark

Line 27 and 28:

x = growthRate( birthRate , deathRate ) ;
population = estimatedPopulation ( growthRate , cPopulation, n ) ;

SHould either be:

x = growthRate( birthRate , deathRate ) ;
population = estimatedPopulation ( x, cPopulation, n ) ;

OR

//x = growthRate( birthRate , deathRate ) ;
population = estimatedPopulation ( growthRate(birthRate , deathRate), cPopulation, n ) ;
Duki commented: thanks for the help! -duki +1
thekashyap 193 Practically a Posting Shark
while ( !airportsMaster.eof())
{
    airportsMaster.getline(icaoChr, 5,',');
    for ( int i=0; i<(numAirports); i++ )
    {
        if (icaoChr == icaoStr[i])
        {
        airportsList << icaoStr[i] << ",";
        airportsMaster.getline(tempChr, 35,'\n');
        airportsList << tempChr << "\n";
        }
    }
    airportsMaster.ignore(35, '\n');
}

You have already extracted teh '\n' on line 10. It really isn't THAT obvious what the code is doing, but my guess is that line 13 should be in an else of the if inside for loop.

thekashyap 193 Practically a Posting Shark

Post your code first.

Salem commented: random rep++ from salem +6
thekashyap 193 Practically a Posting Shark

3. Optimizing the breaking conditions in for loops. If you know that the loop variable's range is from 0 to some +ve number AND it doesn't matter which way you traverse while looping, you can optimize the loop like this:

//original loop
for( int i = 0; i <= 30; i++ )
{/*do your stuff*/}
//optimized loop
for( int i = 30; i--; )
{/*do your stuff*/}
thekashyap 193 Practically a Posting Shark

A few more I find useful...

1. Replace switch-case/if-else with array-indexing:

switch ( queue ) {
case 0 :   letter = 'W';
   break;
case 1 :   letter = 'S';
   break;
case 2 :   letter = 'U';
   break;
}
//or maybe
if ( queue == 0 )
  letter = 'W';
else if ( queue == 1 )
  letter = 'S';
else
  letter = 'U';
//A quicker method is to simply use the value as an
//index into a character array, eg.
static char *classes="WSU";
letter = classes[queue];