Agni 370 Practically a Master Poster Featured Poster

If you are passing the address of result then it's definitely a problem because you have not allocated 'result' on the heap. It's a local variable in the function Union and it disappears when we exit the function, if you try to access that address you can get run-time errors.

Agni 370 Practically a Master Poster Featured Poster

This is a first, a video problem ... what if the video was edited? :) .. Not a good way to learn programming I'd say ...

Agni 370 Practically a Master Poster Featured Poster

Why don't you put some couts and check the values of 'Position' ? and btw you are leaking a lot of memory.

Agni 370 Practically a Master Poster Featured Poster

did you try

try{
        FloatValue a(INFINITE_VALUE);
    }
Agni 370 Practically a Master Poster Featured Poster

Your implementation file needs the 'using namespace std' declaration.

Agni 370 Practically a Master Poster Featured Poster

You need to do 2 things

1> Post the exact error messages here
2> Use code tags for re-posting your code so that it can be easily read.

Agni 370 Practically a Master Poster Featured Poster

And as a rule if your class defines any of these 3 then you probably need all the 3.
1> destructor
2> copy ctor
3> assignment operator

so you can define a copy ctor as well for your class.

Agni 370 Practically a Master Poster Featured Poster

Well if you are getting into programming in c++ seriously, then you need to take a look at passing arguments by value and references and returning values from functions before you try anything else.

Agni 370 Practically a Master Poster Featured Poster

First of all you need to decide if the parameter has to be passed by reference and hence changed or it has to be returned by the function and collected in main. Right now you're trying to do both but nothing is complete. The pointer is being passed by value and the return value of the function is not collected.

Agni 370 Practically a Master Poster Featured Poster

I guess you can look at using the gnuplot library for simple graphs etc. i'm assuming you are working on *NIX

Agni 370 Practically a Master Poster Featured Poster

The only draw back is that at no point of time, the value of any expression exceed one digit.

unfortunately then it would fail to evaluate his original expression of
264+* ...right?

Agni 370 Practically a Master Poster Featured Poster

You don't need to create 3 threads for the same problem. 1 would be enough.

Agni 370 Practically a Master Poster Featured Poster

I don't think you will be able to use the same makefile across UNIX and Windows. What you can do is have 2 makefiles with different extensions like makefile.XP and makefile.Sun and have another sort of a base makefile included in all the makefiles that decides at compile time which of the above makefiles to pick based on env variables like OS_REV, which should be set in the env. file.

Something on these lines might help.

Agni 370 Practically a Master Poster Featured Poster

Please tell be what I did wrong...

#include <stdio.h>
#include <ctype.h>

void input(char *str);
int Ecount(char *str);
void Display(char *str);
void Wcount(char *str);

void main(void)
{
	char S[50];
	int count;

	printf("Input a string: ");
	fgets(S, 50, stdin);
   Wcount(S);
}


void Wcount(char *str)
{
	int i=0, word_count=0;
	while (str[i] !='\0')
	{
		if( isspace(str[i]) && !isspace(str[i+1]))

			word_count++;

		i++;
	}
		printf("\nThere are %d words.", word_count);

}
C:\PROGRA~1\MICROS~1.0\VC>test.exe
Input a string:  she sells sea shells at the sea shore but the sea

Output:[B]There are 10 words[/B]

That seems like a wrong output to me.

Agni 370 Practically a Master Poster Featured Poster

Sure. Just the minor change correcting his loop I get

:) well its getting useless now, I'm sure with 'minor' changes we can achieve a lot with anything.

Mr. OP if you've got what you wanted, please close this thread now.

Agni 370 Practically a Master Poster Featured Poster

Not allowed to use the <string> header?

Agni 370 Practically a Master Poster Featured Poster

If you are taking a C++ course, the code is C++. It's just primitive. No one can expect you to know the difference if your instructor hasn't explained the difference.

If the instructor hasn't explained the difference we can do, and that's why i pointed it out. It was more of a piece of info than anything else.

Also it will still tell you one less than the actual number of words in the sentence. Because you are counting the spaces not the words. eg

Nope. Not with isspace() .

really?? Why don't you take his code, run it as it is and check the output?

Agni 370 Practically a Master Poster Featured Poster

I don't know about you but I am definitely totally confused ;) !!!!

Agni 370 Practically a Master Poster Featured Poster

That's for you to decide whether you want to allocate memory on the heap or on stack. And new returns a pointer so it should be box* b;

Agni 370 Practically a Master Poster Featured Poster

Then you can first move the pointer to the starting of the first word.some thing like this

while (str[i++] == ' '); // move the pointer to starting of first word
while (str[i] !='\0')
	{... your code..
..

What if there are extra spaces at the end of the string? How do you plan to work that?

Agni 370 Practically a Master Poster Featured Poster

Also it will still tell you one less than the actual number of words in the sentence. Because you are counting the spaces not the words. eg

Sentence-> I am a good boy
spaces-> 4, word_count = 4 !!
actual number of words = 5.

You can increment word_count after the loop once more to correct that.

>This looks like a C-code more than C++ and should have been posted there.

Agni 370 Practically a Master Poster Featured Poster

I'm not too sure, but may be this might help. This was done on windows.

#include <iostream>
#include <string>

using namespace std;

int main()
{
	string p;
	while (cin >> p != '\0')
		cout << p << endl;
}

> ls | ./myProg.exe

Agni 370 Practically a Master Poster Featured Poster

This copy ctor is totally screwed

void box(box c) //copyctor (copy constructor)
{
       this.value=c.value;
};

you can't pass the object by value as it will create an infinite loop. Remember the 3 main instances when the copy ctor gets called?, 'pass by value' is one of them. copy ctor should always use pass by reference. 'const ref' will be best.

Nothing much is going on behind the scenes in the copy ctor, you just copy elements from one object to another.

This program is full of errors, I'm sure you will encounter them when you compile it.

Agni 370 Practically a Master Poster Featured Poster

That to me seems like a perfect example of what could go wrong if you don't define a copy ctor for classes which have pointers to memory on the heap. Shallow copy as you said will have the 'data' pointer of both the classes point to the same memory location. Once the local object gets deleted its dtor will delete that memory, 'data' is now a dangling pointer and any access to it can cause segmentation faults, unexpected output etc.

Agni 370 Practically a Master Poster Featured Poster

>Immplementation
for starters you can post well indented code within 'code tags'. like this(read the 'help with code tags')

..
your code

>but I'm having a problem about the main program..
secondly you can mention the exact problem you are facing so we can focus directly at that point.

Agni 370 Practically a Master Poster Featured Poster

It worked for me without any problems.

Agni 370 Practically a Master Poster Featured Poster

http://www.daniweb.com/forums/thread70096.html

some of the books mentioned in this sticky might be freely downloadable, some not.

Agni 370 Practically a Master Poster Featured Poster

malloc returns a void* to the memory allocated and you need to ensure that you type cast it to the correct type.

Agni 370 Practically a Master Poster Featured Poster
Agni 370 Practically a Master Poster Featured Poster

yes please post the code and somebody will def help you. Don't get discouraged by errors, everyone goes through them and in the process of fixing them you get to learn a lot more than what's given in your book. One piece of advice is that don't try to rush into it too fast, before you actually start writing games you will have to learn a lot of basic stuff and hence you should create reasonable timelines for yourself.

All the best.

Agni 370 Practically a Master Poster Featured Poster

hasta la vista baby

Agni 370 Practically a Master Poster Featured Poster

This might be of help
Pickle

Agni 370 Practically a Master Poster Featured Poster

and this will help everyone a LOT !!!

code Tags

Agni 370 Practically a Master Poster Featured Poster

and your attempt is......

Agni 370 Practically a Master Poster Featured Poster

There's a post at the top of the forum Read This before posting. It talks about using code tags and posting well indented and easy to read code. Please go through it.

Nick Evan commented: sounds like good advice to me :) +12
Agni 370 Practically a Master Poster Featured Poster

I think the problem is that you are not setting the 'next' pointer of the last node to NULL. It cab be containing some garbage and giving unexpected results. Can you try this.

void add_to_end(int data)
{
	cout << "add to end" << endl;
	node *temp;

	if (hd == NULL)
	{
		node *new_node;
		new_node = new node;
		new_node->data = data;
		[B]new_node->next = NULL[/B];
		//if I omit the next line then the print function works fine
		hd = new_node;
	}
	else
	{
		for (temp = hd; temp->next != NULL; temp = temp->next){
			cout << "for loop" << endl;
		}

		node *new_node;
		new_node = new node;
		new_node->data = data;
		[B]new_node->next = NULL[/B];
		//if I omit the next line then the print function works fine
		temp->next = new_node;
	}
}

edit:concurrent replies i guess. hope you got the point.

Agni 370 Practically a Master Poster Featured Poster

thanks for that..(i get the message :) ) ... but i was just hoping to get to know someone on daniweb with a first hand experience of it ....

Agni 370 Practically a Master Poster Featured Poster
for(j=0;j<5;j++) 
{
      cout<<"The name List\n"<<name<<"\n";  
}

somehow i didn't feel like replying because it seems like you didn't try to debug this on your own even once before shooting a post here. But just in case its genuine, while outputting also you need to use the subscripts, like name[j].

next time please post well indented code with code tags for specific language.

Agni 370 Practically a Master Poster Featured Poster

fileList = new std::ofsteam(argv);

and you can change 'ofsteam' to 'ofstream' if its like that in your original code too.

Agni 370 Practically a Master Poster Featured Poster

Hi Daniites,

I've been thinking long of joining some open source project but i just don't know how i can do that. If someone here has worked on one can you give me some insights? I need to know how these projects work, how the work is distributed, how is it monitored, on what basis are people selected or rejected, timelines.. etc etc .. I've always thought that they would be way to complex for me and shy away, but i guess i have to start somewhere.

Any pointers would be great.

Agni 370 Practically a Master Poster Featured Poster

Why don't you write a test program to check it?

Agni 370 Practically a Master Poster Featured Poster
savings = new Account[arraySize + 10];

		while(k <= arraySize + 10){
			strcpy(savings[k].accountNumber, temp[k].accountNumber);
			savings[k].balance = temp[k].balance;
			strcpy(savings[k].customer, temp[k].customer);
			k++;
		}

assume 'arraySize' = 5 so savings is an array of length 15. say savings[15], which means savings can go from savings[0]-savings[14]. In the while loop you have k<=15, which means k=15 is valid value, so you try to access savings[15] which is trying to access undefined memory.

Agni 370 Practically a Master Poster Featured Poster

you can use the istringstream class and convert string to int

string a = "byebye";
istringstream s(a);
int i = 0;
s>>i 
...

I think you can try this..

Agni 370 Practically a Master Poster Featured Poster

I know i shouldn't be stretching it more but this is funny .. I'm sure the OP would have become quite a programmer by now... prince of persia :) ...

Agni 370 Practically a Master Poster Featured Poster

thats what i'm saying, fstream provides an interface to read and write data from and to files just like input/output streams. You can open the file and read all the contents in vector of required type(may be a vector of structures) and then compare your value against these values. I'm not sure how to do it otherwise may be someone else can help if you elaborate more on what exactly you want.

Agni 370 Practically a Master Poster Featured Poster

load the names in an array or vector and then do a 'find'?

Agni 370 Practically a Master Poster Featured Poster

I would say you can use the following algorithm

1> convert both the arrays to all upper case or all lower case
2> sort both the arrays
3> compare the contents
4> at first mismatch print 'its not an anagram' and exit
5> else print 'its an anagram'

There will be many shorter one's but this is easy to implement.

homeryansta commented: awesome guy! +1
Agni 370 Practically a Master Poster Featured Poster

>It will then store the alphabetical character into an array ignoring all other character
>compare to see if they have the same alphabetical characters in there.

so first you fetch the alphabets from the input and store it in an array and then check array for alphabets again?? it doesn't make sense to me

do you mean if the alphabets stored in array make any word it will say its an 'anagram'?

Agni 370 Practically a Master Poster Featured Poster

i feel when you do that this error should go, basically I couldn't go beyond because i could never make out which of your files is main.cpp and what is main.h and the includes were equally confusing, so that should be the first step. For dealing with multiple includes use the include header guards.

Agni 370 Practically a Master Poster Featured Poster

>it is not giving me the right answer

and what is the right answer?? what is the program supposed to be doing?? The header doesn't say what it does and i don't want to check the code to find that out.