Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The while didn't work because now you have recursion within recursion. Follow the function through with pencil & paper and you will see why it doesn't work like you wanted it to.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you don't want a while statement, but just a simple if statement

if( x > 0)
   countdown(x-1);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what compiler are you using? It compiled and linked ok using VC++ 2008 Express.

You can't use iostream.h and using namespace std; at the same time.

tux4life commented: Useful post, I did already know it myself, but maybe the others didn't ... +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Hey, its your code, not mine. Where is the main() function ??? Didn't your teacher tell you that every c++ program needs a main() function.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

1) it goes negative because there is nothing to prevent it. Its an infinit recursive function -- that is until it consumes all available stack space and then it will simply crash. You need to add a line that stops the recursion when x == 0 (or whatever other value you want).

2) replace iostream.h with <iostream>. Current c++ standards do not use the .h extension. If you compiler doesn't support <iostream> then get a newer compiler.

3) move that line using namespace std; up above just under the last include directive. It does not good to place it where it is.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

all boost libraries have to be compiled on the target machine. See this link. That is one way they ensure portability.

>>Can I simply make a copy of the .hpp file to the project dir,
or are boost file too much interrelated?

No. You have to build the libraries on the target platform.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

1) get rid of strcmpi() C function. See my version of the == operator below.
2) add #include <algorithm> for the transform() function

3) The friend function is not part of the class, so it has to reference the SortedListNode by SortedList::SortedListNode

#include <iostream>
#include <cstring>
#include <string>
#include <cstddef>//for NULL
#include <algorithm>
using namespace std;

class SortedList
{
private:
	
	struct SortedListNode
	{
		string word;//holds within the word in the node
		SortedListNode* next;//pointer to next node
	};
	
	int size;//number of nodes (words) in the sorted list
	
	SortedListNode* head;//pointer to the sorted linked list of words

	//optional: SortedListNode* tail;//pointer to th
	
	//SortedListNode* locatePosition(string aWord, 

public:
	
	SortedList();
	
	~SortedList();

	int sortedIsEmpty()const;

	int sortedGetLength()const;
	
	void sortedInsert(string newWord);

	void sortedRemove(string oldWord); 
	
	void sortedRetrieve(int index, string& theWord)const;

// Note:  if you want to pass pointers to this function
// then change it to * instead of &, but not both.
    friend bool operator==(const SortedList::SortedListNode& wordA, const SortedList::SortedListNode& wordB); 
};

SortedList::SortedList(): size(0), head(NULL)
{}

SortedList::~SortedList() 
{
	delete head;//and not to forget, use size to walk through the sorted list and delete all Nodes
}

int SortedList::sortedIsEmpty() const
{
    return size;//if size is 0, it returns 0, if size is any other number- it returns 1
}

int SortedList::sortedGetLength()const
{
	return size;
}

void SortedList::sortedInsert(string newWord)
{
	SortedListNode* newNodePtr = new SortedListNode;
	newNodePtr->next = NULL;
	newNodePtr->word = newWord;
	
	if(size==0)//insertion at beginning of List
	{
		newNodePtr->next = head;
		head = newNodePtr;
		size++;
	}
	else//insertion not at beginning of list
	{
		SortedListNode* prev = NULL;
		SortedListNode* cur …
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Spence drew inspiration for the EyeBorg Project from his tiny cellphone camera and his love of The Six Million Dollar Man

I liked that tv series a lot -- apparently got very good ratings because it lasted several seasons and had a spin-off.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

if that w64 structure is what he wants, then he probably doesn't need it -- just use a 64-bit integer such as either __int64 or long long. long long buffer[16384][8] And 2^14 = 64K = 64 * 1024 = 16384, not 16000

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

here is the corrected version :

You have errors.

what are those errors?

but if someone post something just to satisfy his ego over my mistake, that is bad.

All I did was answer your question -- what are those errors, and you get all upset.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I tried compiling that with vc++ 2008 Express, and the Microsoft compiler hates it. It doesn't like the "c\n\t" part.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

sorry, I have no clue what you want.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>if you can have it in memory, then you can have it in a vector.

No it doesn't. If he is still using 32-bit compiler than the size of the long int is not changed from what it is on a 32-bit operating system, and the STL libraries will still be 32-bit libraries. He will need to use a 64-bit compiler to make any use of the 64-bit os.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you obviously are not using MS-Windows or *nix operating systems, because the max amount of ram supported by 64-bit MS-Windows is 128 gig.

one way to do what you want is to store the data in two or more arrays and use one of the arrays depending on the value of i.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Probably -- I've already mentioned three things that you should look at. Could be one of them or none of them. But can't tell you if you don't post the code.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you mean something like this? char array[16384][8] ?

What is a w64 structure?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

why not just fix the problem instead of trying to hide it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

don't clear it before freeing, clear it immediately after using it. The purpose is so that unused elements can be easily detected. For example line 309: before the return statement you have to free up all the memory that was allocated up to that point. If you don't then it will cause memory leak.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I assume you mean you want the file to look somethng like this:

1    2     3
4    5     6
7    8     9

just create a loop to count from 0 to 2 and use fout to save each matric element. After the third element is written then write '\n' to cause next line.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

That certainly works but disables the entire console menu, not just the close menu item.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

yup, without the float typecast and adding .0 to the numeric constants all you get is integer math, which drops all decimals.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

i posted that thing within 2 minutes while i was doing what i was assigned to do at work, all the posts that i send during day time is while working, so i may not have noticed that i missed "else" there. helping is helping and must be encouraged and supported, if i miss "else" there some one has to add "else" to my code and post it again as a refined version, it wont offend me, but if someone post something just to satisfy his ego over my mistake, that is bad.

I'm not trying the badger you, just pointed out that the else is needed in the code you posted. And what are you doing surfing the net while you are supposed to be working ??? Or do you get paid to surf?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

setprecision(2)

#include <iostream>
#include <iomanip>
using namespace std;


int main ()
{
  int c;
  cout << "Celcius: ";

  cin >> c;

  cout.setf(ios::fixed);
  cout << "Fahrenheit: " << setprecision(2) << (((float)c*9.0)/5.0)+32.0 << '\n';

  return 0;

}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

i didnt intend to post perfect version, the one i posted is enough to see where he made the error, what i did is much better than saying "you have errors".

Agreed. :)

the one i posted, compiles and does some operations similar to his goal, so what is wrong?

It displays two shirt sizes. Large was always displayed, which is why you needed the else if

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Learn to use your compiler's debugger and step through the code one line at a time so that you can see what it is doing.

line 292: you are attempting to treat a 2d array of REALIZATION structures as if it were a 1d array. It needs two stars, not one =REALIZATION** generation = 0; . The rest of the code in that function should then work ok.

After allocating the array you need to set all elements to NULL so that they can be correctly free()ed, expecially if the function returns prematurely (see below). memset(generation, 0, generationSize * sizeof(ACTUAL_CHORD *)); lines 309, 330 and 338: memory leak here. You need to free() variable generation and each of the pointers that were returned from spawnRealization().

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 43: should be else if not just else. And what are you going to use those float variables for? If you aren't going to use them then just delete them.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

After a little testing I don't think its possible to prevent someone from closing the console window. I tried the code below with vc++ 2008 Express, but it doesn't work because SetWindowLong() returns 0 and the windows error message is "Access is denied". I assume its a permission thing.

#include <iostream>
#include <windows.h>
#include <string>
using namespace std;
WNDPROC dwPrevWinProc = 0;
LRESULT CALLBACK WndProc (HWND hwnd, UINT message,WPARAM wParam, LPARAM lParam)
{
    if( message == WM_CLOSE)
        return 0;
    return CallWindowProc(dwPrevWinProc, hwnd, message, wParam, lParam);
}

int main()
{
    HWND hWnd = GetConsoleWindow();
    SetLastError(0);
    dwPrevWinProc = (WNDPROC)SetWindowLong(hWnd, GWL_WNDPROC, (LONG)WndProc);
    if( dwPrevWinProc == 0)
    {
        DWORD dwError = GetLastError();
        char buf[255];
        FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, dwError, 0, buf, sizeof(buf), 0);
        cout << buf << "\n";
    }
    else
    {
        string str;
        cout << "Enter something\n";
        cin >> str;
        SetWindowLong(hWnd, GWL_WNDPROC, (LONG)dwPrevWinProc);
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

argv is an array of character arrays so you can't use the > operator to compare a character array with a std::string. What you need to do is

1) junk should be an int, not a std::string
2) use strtol() to convert argv[is] to an int then compare the two ints.

>>I need junk2 to be string becuase i am reading the value of junk2 from a file.

So, read it as an int, not a string. If a string is an absolute must then convert it to an int using strtol() or stringstream.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 14-17: where SMALL, MEDIUM etc defined ?

I think you need to declare just one int variable that can contain the enum variables SMALL, MEDIUM ...

enum sizes {NO_SIZE, SMALL, MEDIUM, LARGE, XLARGE};
    sizes shirt_size = NO_SIZE;

    ...
    if (WEIGHT <=135)
      shirt_size = SMALL;
    else if( WEIGHT <= 165)
      shirt_size = MEDIUM;
   else if( WEIGHT <= 200)
      shirt_size = LARGE;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The problem could be the result of several different things, and no one can tell you specifically without seeing the code. Another possible cause, besides the ones I already mentioned previously, is putting the implementation code in a header file. In that case it will be duplicated in every *.cpp file that uses the header file, thus the duplicate error message(s). The solution is to put the implementation code in one *.cpp file, leaving only the class declaration in the header file.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

maybe you included the same header file more than once and left out the code guards.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what is num ? It needs to be either double or float (link). If it isn't then typecast it to one of these.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

for iostream, many compilers don't evern support iostream.h any more because the ios standards declared it deprecated several years ago.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Actually I started this thread as a spoof on the theory of evolution, not intended to be a serious discussion of anything. If you watched the utube video I posted you would have seen that.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

write a wrapper function such as mywrite() and call it instead of fwrite().

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

ArkM you are making a mountain out of a mole hill. Everyone I know calls files with .h extension "header files". And for windows SDK files I use #include <windows.h> , not #include "windows.h" . And even if we do use the quotes I still call them header files.

You can call them source files if you want to, but I don't think may other programmers do.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

One way to do it is to make an array of strings that contain the words for each number, then index into that array with each digit of the integer. To get each digit of the integer you will need a loop, use the % operator, and the / (divide) operator.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Thanks Narue. Here is my first post. It doesn't appear that I ever posted in Community Introductions. :icon_redface:

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

moved. You didn't say what programming language so I assumed C. Next time don't post tech questions in Geek's Lounge.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

When I joined there were a bunch of know-it-all wannabes running around giving bad advice in the C and C++ forums. I'm fairly confident that my first post was a correction to one of their posts.

The earliest post I can successfully find is on September 26, 2004 (clicky), which is pretty close to my join date, but still short ten days worth of posts.

I can only find the most recent 500 posts I've made. I click on my profile then select the Find All Posts link, and only 500 posts are reported. Is there a way to get them all?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

foo2( ) will also give the size of the pointer, not the array.

You are absolutely right!

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I have over 12,000 posts and can't possibly tell you the first post I made. A search of all my posts doesn't work either because they are no longer on the server, but probably archived off somewhere.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Do you mean the assembly instructions rshit and lshift? The C equivalent are << and >> operators

int a = 123;
int b = a << 1; // left shift by 1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

In You are passing tempdate by value to incrementdate. So the statement tempdate = temp_dat; makes no effect to the tempdate variable of main. So tempdate of main still contain the original string "27-12-2000"

You have two options to rectify this:
1. Pass tempdate by reference:
Either char* incrementdate(int &func_days_int,char **tempdate) and modify it as *tempdate = temp_dat 2. Use the return value of incrementdate in main:

char *newdate = incrementdate(days_int,temporarydate);
free(newdate);

Note that you are using strdup to duplicate tempdate, which needs to be freed.

Third option that I previously mentioned: strcpy(template, temp_dat); parameter template can't just simply be changed to ** because its declared as a character array in main(). So passing a character array by reference makes no sense at all.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

o yes,it is "stdio.h".

what i have learned is that we donot use ".h" in VC2008 like : i use "iostream" not with ".h"

That's not really correct either -- there are thousands of header files with .h extensions used in c++, such as windows.h because there are no equivalent without the .h extension.

The only files I am aware of that lost the .h extension in c++ programs are those in the standard C and C++ libraries. All others still use the .h extension unless the author elected not to use it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Its because you never changed the original value of template, only changed a local copy of the pointer. On line 69 you need to copy -- see strcpy() -- the value of temp_dat into template, not just assign the pointer. Line 71 is completly unnecessary and causes a memory leak. If you want the function to return something, just return template since its a pointer anyway.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

[color][b]

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

must be some other problem because I didn't get any link errors when I put all that code into one *.cpp file and commented out the #include "StackType.h".

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You don't have to change a thing, just pass "I am scr*w?d". I don't think this function should be required to find screeeewed in a larger sentence.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't think that's what he meant. Character arrays passed as a parameter to other functions can be passed as either a pointer or a character array. So the same rule applies to the sizeof() operator there as well

void foo1(char *mystring)
{
   // here mystring is just a pointer, so the sizeof() operator
   // will produce unexpected results
}

void foo2(char mystring[25])
{
   // here mystring is a charcter array and the sizeof() operator 
   // will work as expected
}

int main()
{
    char mystring[25];
    foo1(mystring);
    foo2(mystring);
}