thekashyap 193 Practically a Posting Shark

>> but for some reasons is not working for me

Unable to guess the reasons. Is there ANY output produced when you run this script?

I'm not a batch file expert, but do you REALLY need to use batch file only? If not I highly recommend using something like Cygwin and do the same using a shell script instead.

I also understand that in newer Windows there is something called PowerShell, which is better programmable.

thekashyap 193 Practically a Posting Shark

didn't work

Ppl need more than "didn't work" to understand a problem.

my man

See her avatar? Read: "Code Goddess"?

thekashyap 193 Practically a Posting Shark

Each file is parsed only once. So I didn't quite understand what you mean by 2 passes? If you mean two statements inside the loop instead of one, then they can be combined by removing the temp variable somestr .

>> To generate the SQL:
As I said "You just need to adjust print statement inside the awk once you get it to work."
I.e. the awk on line 8 in my script.

Post your code along with a couple of example input files if you need further help.

thekashyap 193 Practically a Posting Shark

Why not just source the answer file? You could allow for any bash construct at that point. For instance
File: script.sh

#!/bin/bash

VAR="Original"

if [[ $# -gt 0 && -e ${1} ]]; then
    . ${1}
fi

echo "VAR: ${VAR}"

Which outputs just VAR: Original when run with no parameters. BUt provided an answer file such as
File: answer.file

VAR="Modified"

you can run with script.sh answer.file and get the following output: VAR: Modified

Didn't get how this would work? The "answer" file only contains answers, not the variable names (it's NOT property file syntax). It's just a list of values.
See my post with "I'm not the most user-friendly guy" above..

thekashyap 193 Practically a Posting Shark

Why don't you simplify your code? It's looking too complex to understand really.

for myfile in `find . -name "R*VER" -mtime +1`
do
    echo "Processing $myfile"
    # did you mean to use -l instead of -H by any chance?
    # Two conditions on RHS and LHS do not produce similar output.
    somestr=`grep -H ^err $myfile || echo "$myfile:No error"`
    echo "     somestr=$somestr"
    echo $somestr | awk -F~ '{print $1"\t"$2"\t"$7"\t"$8"\t"$9"\t"$10}
done

Usually I recommend to make it work first using simpler syntax, before you try to make it look more nerdy by putting it all on one single line to impress others. :)

Using the tilde (~) symbol as delimiter in the file name, can I extract the fields I want so I get an output like this

Yes. I do not see any restrictions on which char can and can't be used as delim.

I'd like to do this is one pass so I can generate a SQL script with INSERT statements...Can it be done?

Yes, you're already on the correct path. You just need to adjust print statement inside the awk once you get it to work.

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

I was waiting for SoS to to contradict my statements and give reasons for it. :)

Here is what the spec says:
"
A class or interface type T will be initialized immediately before the first occurrence of any one of the following:

  • T is a class and an instance of T is created.
  • T is a class and a static method declared by T is invoked.
  • A static field declared by T is assigned.
  • A static field declared by T is used and the field is not a constant variable (§4.12.4).
  • T is a top-level class, and an assert statement (§14.10) lexically nested within T is executed.

"

Most of the bullets implicitly lead to class loading if the class is not already loaded...

Lets wait for SoS to comment now..

thekashyap 193 Practically a Posting Shark

Static members are init'd when teh class is loaded.
Classloader's forName() method is the one that is supposed to do it.
Exception is when you explicitly ask classloader NOT to init the class but just load it by passing false as second argument to the overloaded forName().

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

If your question is purely on GUI (how to take an expression as input):
- Make a list of functions supported by your code and build a GUI such that user can only use one of those.
- Fix the number of variables supported in an expression (1, 2, ...) and fix names for them (say X, Y, ...).
Let the user build the expressions using keywords from these 2 predefined lists.

If your question is how to represent/process/pass-around/store the expression in the code, then pre/post/in-fix tree are meant for this purpose and you cna use them. See some links here:
- http://en.wikipedia.org/wiki/Calculator_input_methods
- http://en.wikipedia.org/wiki/Reverse_Polish_notation
- http://en.wikipedia.org/wiki/Polish_notation
- http://en.wikipedia.org/wiki/Infix_notation

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

Interesting..
Checking the code now. I suspected maybe it takes time due to it's effort in identifying the "capturing-groups". But doesn't seem to be the case as "(?:[a-zA-Z'-]*[ ]*)*" also takes long enough.

Modified to code a bit to make it more testable.

Would let you know if I find something more.. :)

import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class RegexTest {
	public static void main(String[] args) {
		String input = "Adarsh has been testing this###aaaaaaaa";
		if(args.length == 2) {
			testPattern(args[0], args[1]);
			return;
		}

		testPattern("([a-zA-Z'-]*[ ]*)*", input);
		testPattern("(?:[a-zA-Z'-]*[ ]*)*", input);
	}
	
	public static void testPattern( String patt, String input) {
		System.out.println("\n\nTest string --> \"" + input + "\"");
		System.out.println("pattern = \"" + patt + "\"\n");
		long start = System.nanoTime();
		Pattern p1 = Pattern.compile(patt);
		System.out.println("Compile time:\t" + (System.nanoTime() - start) + " nanosecs");
		start = System.nanoTime();
		Matcher m1 = p1.matcher(input);
		if(m1.matches())
		  System.out.println("Matched");
		else
			System.out.println("Not Matched");
		System.out.println("Match time:\t" + (System.nanoTime() - start) + " nanosecs");
	}

}
thekashyap 193 Practically a Posting Shark

What do you wnat to validate? I.e what's the validation?
Perhaps match() takes a long time due to the generic nature of the regEx you're using.
Pattern.compile() however shouldn't take any longer/shorter as it's not connected to the input at all.

Can you enhance the code you've posted so that I can reproduce the 100% CPU usage scenario with just this RegexTest class?
Have you done step-by-step debug already? Which function-call takes up 100% CPU?

thekashyap 193 Practically a Posting Shark

Yes, please post full code.

thekashyap 193 Practically a Posting Shark

Can you post the exact command line you're using to compile along with compiler errors exactly as reported?

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

How abt rsh? Is that enabled? ssh is just a secure-rsh, so whatever you can do with ssh can also be done with rsh.

thekashyap 193 Practically a Posting Shark

Well, in this case he could explicitly cast the Measurable back to Quiz because he knows that is what he supplied to DataSet, but it wouldn't be a good idea.

Yes. I somehow had the inheritance the other way round in my mind (Measurable implements Quiz).

The entire point of using the interface is to deal with a certain contract of behavior without regard for the class that is implementing it.
It's more appropriate to use the interface type here.

Indeed. @Author: Do this not casting, although both work.

thekashyap 193 Practically a Posting Shark

Can you post the imports you used in each class? Given that Quiz implements Measureable there should not be an error unless you've got 2 Measureable classes in your project.

thekashyap 193 Practically a Posting Shark

The code you posted doesn't have any typcasting problems. Try this and see what gcc does: long* pl1 = (char *)p1; That's the kind of typcast problem I'm talking about.

Aha..
If I may say, that would be stupid.. :)

thekashyap 193 Practically a Posting Shark

could not is correct -- meaning that if you did it then the compiler should probably produce an error for wrong typecast. (can not convert char* to int*, or something like that)

Mine didn't at least.. or is there some other option apart from -Wall that I should use?

[root@forssa kash]# cat <<EOF > a.c
> int main() {
>     int *pi = 0;
>     char *pc = (char *) pi;
>     long *pl1 = (long *) pi;
>     long *pl2 = (long *) pc;
>
>     return 0;
> }
>
> EOF
[root@forssa kash]# cc -Wall a.c
a.c: In function 'main':
a.c:6: warning: unused variable 'pl2'
a.c:5: warning: unused variable 'pl1'
[root@forssa kash]# 
[root@forssa kash]# cc -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --disable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=x86_64-redhat-linux
Thread model: posix
gcc version 4.1.2 20080704 (Red Hat 4.1.2-50)
[root@forssa kash]#
thekashyap 193 Practically a Posting Shark
#!/bin/bash

# does this help?

# Make a list of files to process:
# it is ls -"one" not -"el"
ls -1 >> list_of_files.txt
find /xxx/yyy -name *.txt >> list_of_files.txt

for file_name in `cat list_of_files.txt`
do
  # process the file e.g.
  [ ! -f $file_name ] && echo "$file_name does not exist. Check if it is absolute path or relative path. If it is relative path ensure you are running the script in correct directory."
  echo cp $file_name some_dir
done

# if the list_of_files.txt is very big you can do this as well:
while read file_name
do
  # process the file e.g.
  [ ! -f $file_name ] && echo "$file_name does not exist. Check if it is absolute path or relative path. If it is relative path ensure you are running the script in correct directory."
  echo cp $file_name some_dir
done < list_of_files.txt

PS:
ls and find (depending on arguments) return relative paths, so ensure that either your script is run in the correct directory. Or edit the list_of_files.txt to make all paths absolute.
E.g.

my_curr_dir=`pwd`
ls -1 . >> list_of_files.txt
echo "relative paths:"
cat list_of_files.txt

echo "absolute paths:"
sed "s/^/$(echo $my_curr_dir/ | sed 's/[/]/\\\//g')/" list_of_files.txt
# edit the file itself:
sed -i "s/^/$(echo $my_curr_dir/ | sed 's/[/]/\\\//g')/" list_of_files.txt
echo "absolute paths inside the file:"
cat list_of_files.txt
thekashyap 193 Practically a Posting Shark

In C language the return value from malloc() does not need to be typecast at all. But if you do use typecast then it needs to be typecast to the appropriate type. For example the line 3 you posted the return value of malloc could not be typecast as char* because that it the wrong type.

Is it not "should not" instead of "could not"?

thekashyap 193 Practically a Posting Shark
// it doesn't matter what's the pointer, you've requested the printf to treat it as an integer.
printf("The number is %d",*(char*)p1);
// You'll see the difference if you instead do this:
int main()
{
     int *p1 = (int*)malloc(sizeof(int));
     *p1 = 60;

     printf("The number is -%d-\n",*(char*)p1);
     printf("The char is -%c-\n",*(char*)p1);
     printf("The hex is -%x-\n",*(char*)p1);
     printf("The hex of ptr is -%x-\n", p1);

    return 0;
}

// OUTPUT IS
//
// The number is -60-
// The char is -<-
// The hex is -3c-
// The hex of ptr is -3e2bf8-
//

Casting (of parameter) doesn't really matter (i.e. you can cast anything to anything) as long as you confirm to the type expected by the function to which you pass the parameter.
What matters is how the function tries to interpret the parameter. If you pass an int with value "0" to a function expecting a pointer and the function tries to dereference it, it'll bomb because it tries to dereference 0x00000000.

Brightest example are malloc() / free(),
-- malloc() just reserves some chunk of memory for you, it's up to you to decide how to you want to use that memory. In case above you're using it as (int). But you have the option of using the same memory as a char or long (not wise as sizeof(long) > sizeof(int) ) or ...
-- If you cast the output of malloc() to int and pass it to free(), it'll tries to free sizeof(int) bytes. …

thekashyap 193 Practically a Posting Shark

Post your code..

thekashyap 193 Practically a Posting Shark

Is performance your concern?
Without knowing:
- What defines a grid cell? and
- How you define "overlap"?

I can give general comment that assuming to find out overlapping cells you'll have to compare all cells with all other cells, I suggest
1. some struct with better random access (vector, array, ...) instead of linked list.
2. sort the list, it always helps the search.

thekashyap 193 Practically a Posting Shark

Can you post your code? If you have implemented the search using recursion you won't need to store the parent info inside each node.

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

Thank you for your help. I mentioned previously that the error isn't a compile error, it's a red squiggly line error that comes up when I hover my mouse over the second instance of the word VendingDisplay in:

VendingDisplay::VendingDisplay(VendingMachine v)
{
	vend=v;
}

When I actually press compile, I get the following error messges:
1>ClCompile:
1> VendingDisplay.cpp
1>c:\users\tangent\desktop\vend\vend\cigarette.h(5): error C2011: 'Cigarette' : 'class' type redefinition
1> c:\users\tangent\desktop\vend\vend\cigarette.h(5) : see declaration of 'Cigarette'
1>c:\users\tangent\desktop\vend\vend\vendingmachine.h(9): error C2011: 'VendingMachine' : 'class' type redefinition
1> c:\users\tangent\desktop\vend\vend\vendingmachine.h(9) : see declaration of 'VendingMachine'
1>c:\users\tangent\desktop\vend\vend\vendingdisplay.cpp(8): error C2027: use of undefined type 'VendingMachine'
1> c:\users\tangent\desktop\vend\vend\vendingmachine.h(9) : see declaration of 'VendingMachine'
1>c:\users\tangent\desktop\vend\vend\vendingdisplay.cpp(8): fatal error C1903: unable to recover from previous error(s); stopping compilation
1>
1>Build FAILED.
my files are:
VendingDisplay.cpp:

#include <vector>
#include "VendingDisplay.h"
#include "VendingMachine.h"
#include "Cigarette.h"
//#include "VendingMachine.cpp"

VendingDisplay::VendingDisplay(VendingMachine v)
{
	vend=v;
}



void VendingDisplay::DisplayMenu()
{	
	int userInput;
	cout << "===~' Welcome To The CigMaster2000 ===~' " << endl << "Please chose from the following options: " << endl;
	for(int i=0; i<vend.getListSize();i++)
	{
		
		cout << i+1 << ": " << vend.cigAtvalue(i).printName() << "  $" << vend.cigAtvalue(i).printPrice() << endl;
	}
		cin >> userInput;

		if(respondToUserInput(userInput)==0)
		{
			processOrder(userInput);
		} else
		{
			DisplayMenu();
		}
	
}


int VendingDisplay::respondToUserInput(int input)
{
	char yesOrNo;
	for (int i=1;i<=vend.getListSize();i++)
	{
		if (i==input)
		{
			cout << "Please confirm the following (Y/N): " << vend.cigAtvalue(i-1).printName() << "  $" << vend.cigAtvalue(i-1).printPrice()<< endl;
			cin >> yesOrNo;
		}
	}
		if (yesOrNo=='Y')
		{
			return 0;
		}
		else
		{
			return 2; …
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

First, I'm wrong in saying that Object1 = Object2 would invoke copy c'tor. It doesn't. It invokes the operator = . So everything I said is irrelevant.

I would still like understand the problem. So could you please post your code which caused error? VendingMachine/Display and main. Thanks.

Sorry I don't understand what you mean by "don't have only some non-default c'tors for VendingMachine".

That was a typo, what i meant to write was "you have only some non-default c'tors for VendingMachine".


Also I suggest you read up a bit on what c'tors are called by compiler at what point. Your code isn't optimal.

thekashyap 193 Practically a Posting Shark

Wha? He does have the default,..

I don't see VendingMachine.h/cpp posted, so I don't know how you say that.
My thought process is:
- vend=v requires copy-c'tor.
- If you define a c'tor explicitly compiler doesn't generate any for you.
- If you define no c'tors in VendingMachine compiler generated ones would do, else not.

But I do think to know the place where the error was reported would help as my first guess was also that the problem is not the code that's posted so far..

thekashyap 193 Practically a Posting Shark

My guess is that you don't have only some non-default c'tors for VendingMachine. That could cause a problem.

thekashyap 193 Practically a Posting Shark

A bit surprising.. It works for me even when VendingDisplay is defined in the cpp instead of header.
The error that you said VS gives you "error:no instance of overloaded function VendingDisplay::VendingDisplay matches the specified type", which line number did it correspond to?
When you do MyClassInstance1 = MyClassInstance2; copy c'tor would be invoked. It's been a few years I touched C++ but as far as I remember there is always a default copy-c'tor generated by compiler. If you want non-default (e.g. you want to assign one instance of VendingDisplay to another) that's when you specifically need to create a copy-c'tor.
Anyway, I don't even see when it should fail (copy-c'tor or not).
NOTE:
My VendingMachine.h

#ifndef VENDINGMACHINE_H_INCLUDED
#define VENDINGMACHINE_H_INCLUDED

class VendingMachine {
};

#endif // VENDINGMACHINE_H_INCLUDED

PS: Add include guards or #pragma once in all headers.

thekashyap 193 Practically a Posting Shark
thekashyap 193 Practically a Posting Shark

You can mark it as solved if it's solved.

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

What is choice defined as?

thekashyap 193 Practically a Posting Shark

Can you post the full command with output? Also re-post the code you're compiling, just to be sure..
I'm using gcc.

thekashyap 193 Practically a Posting Shark

Thanks for your reply but still same problem,, below error messgae

finame.c: In function ‘main’:
finame.c:12: error: ‘op1_log’ undeclared (first use in this function)
finame.c:12: error: (Each undeclared identifier is reported only once
finame.c:12: error: for each function it appears in.)

Probably because of missing #includes..
Code I posted in my second post works for me.. haven't executed but it compiles with warnings.

thekashyap 193 Practically a Posting Shark

HINT: You should ideally check if CORE is defined or not. So better code is:

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

#define STR(x)  x

int main()
{
        FILE *fp;

        char filename[30];
#ifdef CORE
        strcpy(filename,STR(CORE));
#else
#error "Must provide -DCORE=value while compiling this file."
#endif

        fp = fopen(filename,"w");

        printf("%s\n",filename);
        if(fp == NULL)
                printf("Can not open File\n");
}

Source: gcc
You can also provide a default value using "#define"

thekashyap 193 Practically a Posting Shark

Space between -D and CORE is the problem

$ gcc -o finame -DCORE="op1_log.txt" finame.c
thekashyap 193 Practically a Posting Shark

Put the code in the code snippet section.. Next time I can just give a link to it.. :)
Mark the thread solved if there is nothing further..

thekashyap 193 Practically a Posting Shark

>> but then i can't use the total length of the number?
>> except if i take different trees for every number length?
Not sure what you mean..
You can bind all "branches" to a dummy root node if you like (which actually could be "0").
Why do you want/need to use the full length of the number? Once you reach the leaf node, you're assured of finding the correct country name.

PS: I checked the codes, I saw that it's guaranteed to have NO overlaps. I.e. you can't have 2 codes, where code1 is a substring of code2.

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
package com.kash.test;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

	public static void main(String[] args) {
		String s = "ftp://anon:bah@111.222.333.444:9999/path1/path2/";
		String pattern = "^ftp://(\\S+):(\\S+)@(\\S+):(\\d+)(\\S+)$";
		Pattern p = Pattern.compile(pattern);
		Matcher m = p.matcher(s);

		/*
                 * ------------THIS COMMENT IS STILL VALID------------
		 * ..call m.matches() or m.lookingAt() or m.find() here..
		 */

		if (m.matches()) {
			for (int i = 0; i < m.groupCount(); i++)
				System.out.println("Group" + i + ": " + m.group(i));
		} else {
			System.out.println("\"" + s + "\" did not match \"" + pattern + "\"");
			System.out.println("so if I call m.group() it'll throw IllegalStateException !");
		}
	}

}

Output produced:

Group0: ftp://anon:bah@111.222.333.444:9999/path1/path2/
Group1: anon
Group2: bah
Group3: 111.222.333.444
Group4: 9999
thekashyap 193 Practically a Posting Shark

1. Matcher.group() throws IllegalStateException - If no match has yet been attempted, or if the previous match operation failed.
In your case you haven't attempted to match before calling group(). So the exception.
2. If attempted match fails group() still throws IllegalStateExc...
Hope the following clarifies:

package com.kash.test;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

	public static void main(String[] args) {
		String s = "ftp://anon:bah@111.222.333.444:9999/path1/path2/";
		String pattern = "^ftp://(/S+):(/S+)@(/S+):(/d+)(/S+)$";
		Pattern p = Pattern.compile(pattern);
		Matcher m = p.matcher(s);

		/*
		 * ..call m.matches() or m.lookingAt() or m.find() here..
		 */

		if (m.matches()) {
			for (int i = 0; i < m.groupCount(); i++)
				System.out.println("Group" + i + ": " + m.group(i));
		} else {
			System.out.println("\"" + s + "\" did not match \"" + pattern + "\"");
			System.out.println("so if I call m.group() it'll throw IllegalStateException !");
		}
	}

}
thekashyap 193 Practically a Posting Shark

what I've given should solve the problem..
If you have more probs, post your code

thekashyap 193 Practically a Posting Shark

Which shell?
What's the loop break condition?

How to loop: http://www.freeos.com/guides/lsst/ch03sec06.html
How to call a script: It's just a command give full path.
E.g. a.sh wants to call b.sh then

#!/bin/bash
#a.sh
PATH_TO_B=/tmp/b.sh
echo Calling b.sh
$PATH_TO_B
echo $PATH_TO_B exited with $?

#if b.sh is not executable then:
/bin/bash $PATH_TO_B
echo $PATH_TO_B exited with $?