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

Your error check is not going to work. Why? Because if someone enters more than 16 characters then the entire program will get trashed and there is nothing that you can do to avoid it. That's one of the problems with scanf().

What I would do is get the string one character at a time and produce an error on the first character that would overflow the destination character array.

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

character arrays that are created on the stack like iReturn[] can not be returned because they are destroyed as soon as the function returns.

You have two options

1) Have the calling function create the array and pass it to GetBase2() as a parameter, such as char* GetBase2(int iBase, int iNumber, char iReturn[]) . Note that the function return is char*, not just char


2: Make iReturn a pointer, allocate it with malloc(), return it like you tried to do. In this case, the calling function -- main() -- will have to free it when done with it. char *iReturn = malloc(64);

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

1. exec gives you a lot more control, look in the man pages or use google and you will find all the different ways exec can be used.

2. Either redirect the output such as system("data >filename.txt") to a file or use pipes.

3. Why not? For each fork() you get a new process. Why would you want more than one process for each fork()? That would be just nuts. You can create as many processes as you want by calling fork() numerous times.

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

lines 8 and 9

int i, max_val; 
    double x[max_val];

What is the value of max_val? What is the size of array x?

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

call the funciton isprint()

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

you don't have to convert anything -- just write the array to a file as it is. BTY: you can not write bits to a file -- only bytes.

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

Look at the function kbhit() in conio.h, which is non-standard and not supported by all compilers.

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

That would be "implementations" rather than "versions". The term "versions" implies that they're derived from a common source. (I don't recall a recent "curses" library on MS-Windows which wasn't one of the other two).

Yea, right. "implementations" would have been a better choice of words.

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

Odd -- I could have sworn that this problem as asked and solved over a week ago.

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

There is no standard C or C++ way to do that. There are a couple non-standards methods, depending on the operating system. For MS-Windows compilers you might look to see if your compiler supports conio.h. It has functions such as kbhit() that checks to see if something is available at the keyboard. Then there's curses, pdcurses and ncurses which are three versions of the same library and available on both MS-Windows and *nix.

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

What is the effect of the following code?
main()
{
int option=4;
switch(option/2)
{
case 1: printf("EAST");
case 2: printf("WEST");
case 3: printf("NORTH");
case 4: printf("SOUTH");
}
}

Hint: there are no break statements between the cases.

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

You are asking about how to flush and discard the input stream of all its contents. Narue wrote this thread some time ago that explains how to do that.

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

Please post your question(s) here. I will not respond to PM.

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

Number of iterations? Infinite. Why? because 1/2 = 0 (integer division) so the value of x will never change.

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

Oh I see. You need to make it like this: void print_hello(int n, int ch); and use the variable ch instead of hard-coded stars. That would make the print statement in my previous post like this: printf("%c%cHello World%c%c", ch,ch,ch,ch); where each %c tells printf() to get the character from the parameter.

You also need to change the function prototype at the beginning of your program.

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

When EOF is reached you have to call rewind(fp) to move the file pointer back to the beginning of the file so that it can be read all over again. But why??? Two loops are completely unnecessary and a waste of CPI time. Use an array as Adak suggested and you can do it with only one read of the data file. Your method would require 100 reads of the file :icon_eek:

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

Yes and this thread is 12 days old and still Dani has taken no action. How long do we need to wait before such a feature will be introduced?

She already has taken action. This topic has been discusses several times over the last 5 years that I have been a member. Dani has consistently stated she will not do it.

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

jephthah, as new member of the forum I'm just trying to fit in and try and not upset all the people who have been here for a long time so apologies for replying to an 11 day old thread - at least I now know that even if I can help someone I shouldn't reply to any threads older than 10 or 11 days.

You normally will get bad rep if you bump a thread that has been dead for 6 months or longer. 10 or 11 days is ok. We've seen some people bump 5-year-old threads, most likely because they didn't pay attention to the date of the last post.

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

What the hell makes you think I'm going to do your work for you? I have my own to do.

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

>>/N=7 2^N=128

That is bytes, not bits (see this link). 128 bits is 16 bytes on computers where 1 byte is 8 bits.

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

Now if only the OP will understand the significance of your post and how easy it will make his program's solution.

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

case statements must be constants. You can not use variables there

switch( some_variable )
{
case 'a':
  // blabla
  break;
case 'b':
   // blabla
   break;
case 'c': case 'd': case 'e':
   // this for all three characters
   break;
<etc. etc for each letter you want to support>
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>void print_hello(int n, int *)
What is that second parameter for?

All that is doing is printing one line of * below the text. What about above the text and on each side?

****************
** Hello World ***
****************

This is how to do it

  1. Print the top line
  2. Print two *, then the text, then the last two stars, such as printf("**HelloWorld**\n");
  3. Print the last line

You can not do that all in one big loop.

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

Ok, sorry I misunderstood. I won't be able to look at it again for the next 36 hours (sleep + work + honey-do-list).

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

I never create a pointer to a vector -- pointer here is just not necessary. Your third example is the most common way to do it.

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

One of the problems is that when the current value (509) is less than the value at the root (913) there is no provision to insert the new value at the root of the list. Instead, it inserts it at t->left, but it should be added at t. Learning to format your program better to make it more readable might help you understand what is going on

BinaryNode *BinarySearchTree::insert(int x,
BinaryNode *t) 
{
    static long count=0;
    count++;
    if (t == NULL)
    { 
        t = new BinaryNode(x,count);
        count=0;
    }
// t->key == 913 and x = 509
    else if (x < t->key)
    {
      // this is wrong when x < t->key
	    t->left = insert(x, t->left);

    }
    else if (x > t->key)
    {
	
        t->right = insert(x, t->right);

    }
    else
        throw DuplicateItem();
    return t;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
int count[101] = { 0 }; //assign all elements to zero value

if (your char is a number from 1 to 100)
  count[char + '0']++;

//remember count[0] will not be used here.

Your example is just a little bit wrong. The file contains integers, so if they are read as ints then no conversion is necessary

int count[101] = { 0 }; //assign all elements to zero value

if (the value of the integer is a number from 1 to 100)
  count[number]++;

//remember count[0] could be used here if the value of the
// integer in the file were 0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You need to add a constructor to Rectangle that takes no parameters -- that's called the default constructor.

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

You have made that problem a lot more difficult than it needed to be.

int compare(const void  *x,const void  *y)
{
	return(* ((int*)x)-*((int *)y));
}

int qsortselect(int keys[], int n, int size)
{
	qsort(keys,n,sizeof(int),compare);

	int x = keys[size];
    return x;

}


int main()
{
	int A[5]={3,5,67, 7, 2};

	for(int i=0; i<5;i++)
	{
		cout << A[i] << " ";
	}

	int stat = qsortselect(A,5,2);

	cout << endl << stat << endl;

	getch();
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

... you tell some kid to get off your lawn.

Funny you mentioned that -- my wife has a reputation among the neighborhood kids. We once heard one kid tell another "Don't walk on that woman's lawn because she's mean!" :)

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

It's more accurate to say that Notepad doesn't know anything about fonts. Notepad is worthless. Forget that it exists.

Notepad does now (win7) and I think it did in previous versions too. Menu Format --> Font. But it uses the same font for everything.

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

using vc++ 2008 express I get a lot of these warnings
warning C4290: C++ exception specification ignored except to indicate a function is not __declspec(nothrow)

The Parser.h you include in main.cpp -- it that one of your header files? There is also one in the Windows SDK, which is the one that vc++ 2008 express is picking up.

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

Its not possible in any language. Files don't know a thing about fonts. As for Notepad.exe I know of no way to change it from a c program.

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

>>but don't kn0w how t0 apply it for 3 c0nditions ?

Is the o key broken on your keyboard? if( a > b) ? a : if( b > c) ? b : c; You could in theory just keep going on an on like that, but it will just make the code nearly impossible to understand.

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

You need to also post RuntimeException.h and its corresponding *.cpp file if there is one.

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

Post entire code so that we can compile and test it.

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

>>static long count;
>>count++;

Your program is incrementing an uninitialized integer and then you use that integer later on in the function. initialize it to 0 static long count = 0;

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

>>Can someone help me with this????

Help you with what? We don't do homework for you -- that's your job as a student.

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

>>- i want to know if this is possible

Why not? You could also declare them as int a, b, ab; . If you put that in a header file then you have to use the extern keyword in the header file, e.g. extern int a, b, ab; then do the same thing in one, and only one, *.c or *.cpp file but without the extern keyword. extern tells the compiler that the integers will be actually declared somewhere else. If you don't use extern in the header file the compiler will puke up errors that the integers have been multiply declared ... in each *.cpp file which includes the header file.

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

- Hollywood gave them gloss and just HAD to set them in the US, totally ruining them in the process, *sigh*.

That's Hollywood for you :( They did the same thing with Dr. Who.I'm sure glad they didn't get ahold of the Godzilla movies. Oops! I think they did.

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

If you used c++ <vector> class you would not have to worry about it because that class will do all the expanding for you. But if this is homework then you may or may not have that choice.

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

I found setjmp and longjmp quite useful in database programs to quickly return errors between deeply nested function calls. c++ exceptions are the alternative in c++ programs. goto is only useful within the same function. setjmp and longjmp are between functions, although could be used within the same function too.

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

>>s this code portable between operating systems

No. Works only on MS-Windows because it appears to be using win32 api functions. There is no portable way to do what you want using any standard C or C++ functions. There are non-standard functions, such as ncurses which I know has been ported between MS-Windows and *nix. Functions in conio.h may also do it, but that is not only os dependent but also compiler dependent.

>>Any reason why it wouldn't be a good idea to use?
Depends on the compiler you are using. Since you brought up portability then you probably don't want to use that.

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

>>with only a few sick days per year!
What sick days?? :) Don't be fooled by that Solved Threads count. The count gets increments for all threads that I post in, whether I helped solve them or not. The absolute post count is a better gauge of someone's activity. This topic has been discussed several times in DaniWeb Community Feedback forum.

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

There is no one place. For *nix its normally the man pages. You can access them by googling "man function_name". For MS-Windows it would be MSDN. You can also just google for the c++ container class, e.g. fstream. If you want the absolute authority then you will have to BUY a copy of the ISO C++ standards, but from what I have seen of it it's somewhat difficult to read, intended for compiler writers.

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

Read this to research your question. There are a few links to games at the bottom of that link you might want to read. I have not read them so I don't know what they contain.

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

>>It appears to me almost that a BSTR could be used very similiarly to a VARIANT in Visual Basic

Not really. C also has a VARIANT structure which, among other things, contains a BSTR. The VARIANT is an enumeration of a lot of different pointers and data types. In C its main purpose is for COM, but can be useful to VB as well. When VB passes a string to C it is usually BSTR.

>>and the SysStringLen() is 8!!!!

Why? Should be obvious is you look for that function in MSDN. That function expects the BSTR to contain a UNICODE string (wchar_t*), which in your case it does not (char *). As I said previously, you, the programmer, are responsible for the contents of BSTR, and its up to you to use the appropriate win32 api functions to deal with it.

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

I used to watch Big Brother but it was cut off the air. I hope Big Brother (Australia) comes on in the near future as it was a great show. I still remember the ending "This program is brought to you by Dreamworld, the home of Big Brother". Wish it were still on or that I could get live streaming of an international Big Brother.

I hated American version of Big Brother. How boring to watch a bunch of people visit each other in a house. Its more interesting to visit an old people's retirement home :)

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

just cd to root and issue find command

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

There are SOOO many to choose from!

Murder She Wrote
Diagnostics of Murder
Law & Order Criminal Intent
Law & Order Special Victims Unit
House
ER
Golden Girls
MASH
I Love Lucy
The Honey Mooners
Upstairs Downstairs
Benny Hill
Dr Who
All Star Trek series and movies
BattleStar Glatica
Jack Benny
The Jeffersons
Merlin
Biggest Loser
American Idle
America Has Talent