WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

i made a bubblesort function

void BubbleSort( const char *array[] , int size )
{
 
    int result;
 
 for ( int next = 0; next < size - 1 ; ++next )
 {
  for ( int j = 0; j < size - 1 - next; ++j )
  {
                result = strcmp (array[j], array[j+1]);
 
                if (result > 0)
     swap ( array[j] , array[j+1] );
  }   
 }
}

and in the main i just did the cout...

This is a perfect Bubble Sort. Now all you have to work on is your formatting ;)

void BubbleSort( const char *array[] , int size )
{
 
    int result;
 
    for ( int next = 0; next < size - 1 ; ++next )
    {
        for ( int j = 0; j < size - 1 - next; ++j )
        {
            result = strcmp (array[j], array[j+1]);
 
            if (result > 0)
                swap ( array[j] , array[j+1] );
        }   
    }
}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Here's what I think is a correct version of your function. Look at this version versus yours.

I disagree on principal. She already has a function called findeaverage() so why would you want to make a do-all function? They are harder to debug and maintain. Take each piece you want to accomplish and make a function out of it. Return one value from each with the return statement.

And change the name of array1. It's not an array. Call it cout.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I would go about it differently

Loop thru words first to last-1, index is IDX1
{
    set FLAG to True
    Loop thru words IDX1 to last, index is IDX2
    {
        if word(IDX1) = word(IDX2) then
        {
            set FLAG to False
            break out of inner loop
        }
    }
    if FLAG is True, display the word, there is no duplicate
}

This way you will not print the duplicates if there is one further down the list -- you print the last occurence of each word. This will give you
two
one
three
four
five

Then you can work on your last step about sorting.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

HI,
Thanks to Everyone for giving me the solution. Please Let me Know Should i used Borland or MS VC++ for compling this code.

Either. Both have their good and bad points. I personally use Borland 5.5 but I'm very used to the command line. Bloodshed DevC is also good. If you already have M$, that will work fine.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Hi,

Download that Zip file And Goto Project Properties -> Make
StartUp Object = scientific.

its a good code.. No need to Re-Invent the wheel

Regards
Veena

Excuse me, but if you give them code to a project they want to do, how can they possibly learn how to program? All code that people learn from has already been written. Why did you invent the wheel when there were many other calculators available? Including mine? ;)

And people (everyone that has posted in this thread), please read this section of the DaniWeb RULES.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
#include <iostream>
#include <cstring>

int main()
{
	char wordArr[5][10];
	bool contr = false;
	size_t i, j;

	for(i = 0; i < 5; i++)
		std::cin >> wordArr[i];

	for(i = 0; i < 5; i++)
	{
		for(j = 0; j < i; j++)
		{
			contr = strcmp(wordArr[i], wordArr[j]);
			// If the above line sets contr to true or false...
			if (contr == true)    // what are these two lines for?
				contr = true;
		}
			if (contr == false)
				std::cout << wordArr[i] << '\n';
	}

	std::cin.ignore(2);
	
	return 0;
}

What is it you are trying to do?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Absolutely right. I have been working for my employer for about 8 years now and we have completely re-written the program three times due to hardware changes (upgrades with new os versions). And we are about to do it again in a couple months.

Good thing programmers are extremely adept at plagerism. ;)

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Choose a console application. That's the easiest to start with.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I'm a relic from the '80s as well, nothing wrong with relics.
Most of us have a fair number of faithful followers who really believe in our powers, or at least are admired for our beauty :)

That's true. I myself predate the PC and C. But it's the relics that are teaching hieroglyphic era code rather than today's concepts that does neither the industry nor the students any good.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Does it seem to work when you compiled it? ;) That's your first test. Narue is correct.

Every character is simply a number that displays as a character. For example 'A' is 65, 'B' is 66, so they can be treated as numbers.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

If I was an oracle...

... you'd be tough to talk to and the interface would be heck! Most of us don't speak SQL :D

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

As for the brown sauce, it's also known as 'chop sauce' or 'meat sauce' and is best known in brands such as 'Daddies Sauce' which probably hasn't helped pin it down much...

I wonder if it's similar to our A-1 steak sauce.

I actually quite like British food: I had the opportunity to experience it firsthand on many occasions from a couple from Yorkshire. People in the States always ridicule English food saying it is "bland"-- I don't agree.

And The Fat Duck in Berkshire has become the best restaurant in the world... So much for the British having bad food ;)

Upper midwest for me (Minnesota), America's home of Lutefisk and Lefse. Yummmm.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Muffin Master, who

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

It really worked, Narue :)

Yep, Narue's good! Welcome Back!

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

>I still have some errors and I can't seem to figure out the mistakes TY for all your help
I refuse to read your code until you format it and put it in code tags.

And don't let us try to figure out what the errors are. Tell us. It's not our program.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Maybe even I should attempt and post the solution to Professor WaltP.

Yay atlast we get a qualified teacher who balks at void main ( ) :D

I don't like your attitude. Spit out that gum and sit in the corner... :twisted:

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

and why are you using a 20 year old compiler?

Pssst..dont let Mr. WaltP hear about that....:cheesy:

:mrgreen:

I'll bet it's because the instructor is a relic of the 80's and refuses to update his knowledge so his students can program in today's market. Especially since 15 years ago Borland removed graphics from the compiler and all the Borland-specific functions that he's teaching. So he must use an old compiler -- he doesn't want competition if he ever decides to go back to the industry :rolleyes:

manoj201jain, you have to compile the program with the graphics library graphics.lib on the build line and include graphics.h in the code.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I've PM'ed it to WaltP for verification.

Yep, it'll work, for strings of a max length. You certainly have a different style than me :mrgreen:

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Possibly, but it's not obvious. Somewhere you have to keep track of the the number of 'S's removed. The only thing I can think of is using recursion.

Search for an 'S' adding one to the pointer. When you find the 'S', call the function again using the current pointer location. Keep this up until you get to the trailing '\0' then return.

When you return,
copy *ptr+1 to *ptr, increment ptr, and stop when you copied the '\0'
Then return again.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Whenever I use #include<gl\glut.h> Borland tells me it is unable to open include file and Visual C++ gives me 'undeclared identifier' error
I feel sure I have all relevant .h, .lib and .dll files in the correct place.

When using Borland:
GL Files address: C:BORLAND\BC55\INCLUDE\GLUT.H

When Using Visual c++:
GL Files Address: C:PROGRAM FILES\MICROSOFT VISUAL STUDIO 8\VC\INCLUDE\GLUT.H

You specify #include<[B]gl\[/B]glut.h> , so where is the GL directory, since you told the compiler that's where the file is?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Those are similar to my hours, especially now that the bowling alley is open and it closes at 1 am.

Gee, so after 1AM you can just go here :D

I goto sleep at 12:30-1am and wake up around 7:30-8am.

7AM?!?! Heck, Life begins at Noon!

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

"Open the gates!"

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

How much experience do you have in C or C++? What OS are you using? What compiler are you using?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Clarification:
1) You do not wish to use ANY local variables at all, so the only variable allowed in the function is the pointer to the string.
2) Using another function is not allowed.
3) You want to remove all 'S' characters, not just the first with this function.
4) Is this homework?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Whenever I use #include<gl\glut.h> Borland tells me it is unable to open include file and Visual C++ gives me 'undeclared identifier' error
I feel sure I have all relevant .h, .lib and .dll files in the correct place.

What is the FULL disk and path of the GL files that can't be found?
What is the FULL disk and path of the source code you are trying to comple?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

But tell me, can using

void main ()

ever cause undefined behavior in a program?

Ever? Yes. See this

Under normal circumstances, though, no. But since it's wrong, don't use void.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Hello! here is what I wanna do:
I have a while() statement, and inside of it I have some instructions to repeat. My problem is that, I want somehow to stop that loop ONLY when I press a key... I it's kinda like getch() but getch() waits for a keypress.... Any help is appreciated :) Thanx in advance.

I assume you have getch() available. Not all compilers do, making any code using it non-portable. But if you do, look to see if the compiler has a function called kbhit(). That's the function you're looking for.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Oh, you're right! I just got a new star recently, didn't I? :)

New star?!?! How come you rate so... Oh, yeah. I forgot... :o

And because of this, the Game Development Board would IMO be geared not to 'coding problems' but higher level 'gaming concepts', whereas "I need help on my TicTacToe homework" is a C/C++ problem.

Of course, this will cause some consternation in new posters when they do need help with their TicTacToe homework because, as we all know, new useres rarely read anything except the title of a forum and rarely read all the way to the description.

Err..so are you with us?

As far as having a game forum, sure. As for helping, no knowledge.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

<Dani takes off admin hat> But the original thread starter finished his project already, so there's no harm still discussing the topic and letting things into a deeper conversation about it. (Since the original fella was already helped, afterall) I've gotta convince you to stop thinking of the forums like a support ticket system and lighten up by letting conversations flow naturally. ;) :p :cool: <Dani puts admin hat back on>

Very good point. I had glossed over the fact that the project was finished... Sorry.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

In my field of Software Engineering, even though math comes easy for me, I never really needed very high-level math. I can take an equation and develop the code to compute the answer. In a sense, the equation is the description of the problem, and that's generally easily converted into code. But in graphics, math is relatively important -- you're always dealing with geometry and algebra. But on a team, you generally get the part of the project you're good at. If that's not math, that part goes to someone else.

As for female and age, should not be a problem.

Stressful or laid back? Yes. It can be both. As with any industry, when you have deadlines, there can be long hours and stress. At the beginning of projects it can be laid back, hectic, fun. Lots of good mental work figuring out the best way to handle the project, then design it. Then the coding starts.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Put cout statements at the beginning of rek() and after the statement that calls rek() again. Print out all the values you're interested in (i and s) and watch what prints out. Then you can see what is happening.

s+= rek (i/10)+i%10;

Each time you arrive at this statement, if i is not 0, rek() is called with i/10.

When i reaches 0, s is rounded and returned. Then the last digit if the current i is added to the returned s, and that value is added to the current s.

Basically, you have a confusing function. To make it a little more understandable, and you can display more values, you could change the function to:

int rek(int i) 
{
    double s=0.9;
    if (i)
    {
        s+= rek (i/10);
        s+= i%10;
    }
    return int (s+0.5);
}

This simply separates the compund statement adding to s. To follow the program, add the cout's:

int rek(int i) 
{
    double s=0.9;
    cout << "entered  rek -- i=" << i << endl;
    if (i)
    {
        s+= rek (i/10);
        cout << "returned rek -- i=" << i << "  s=" << s << endl;
        s+= i%10;
        cout << "     % added --  i=" << i << "  s=" << s << endl;
    }
    return int (s+0.5);
}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Is there possibly a happy medium?

Yes, and I explained that to may4life. He seemed to understand, then ignored me.

As JoeProgrammer suggests

So if they're only stuck on one idea or concept, why not help them specifically with that part, instead of showing them the entire program? If they are capable of writing *most* of the program, let them do that. Let them get experience with that part. If they are truly stuck on a part, explain to them how to do it AND give them a code example. That's the best way of teaching someone.

Key word -- example! I go as far as to say that example does not even have to solve their problem, but shows a technique that they can use to solve it themselves.

may4life's argument is if you give them a working solution, the people that really want to learn will. I completely agree. It's the other 50-60% of them I don't want passing on someone else's work. There are enough hacks in the industry already. We don't need more graduates that barely know what they are doing because rather than figure it out, someone else does their work for them. It's these people that should not be given code. And if you really want to learn, they don't want it written for them. Therefore, the common denominator -- don't give working solutions. Give examples that explain the idea and let them solve it themselves.

I am a "newbie" - …

John A commented: Ahh... couldn't have said it better. -joeprogrammer +3
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Does anyone know what is the best function to use if you want to read user input and not have the return key carry over? Everytime I write something that reads in two things, the second read in always ends up being '\n' because the return key carries over to the next input.

It actually depends on what you're reading and how. Some functions leave the \n in the read buffer, others do not. Some functions ignore \n for certain data types, but not for others. Give us an idea what you are reading and how.

Since you didn't specify, my guess is you're using scanf() to read numbers and characters. This has always been a problem. SOS has a very workable solution if this is the case.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Let's make this more interesting...

Can anyone help me write the code for the same removeSfromString function without taking any local variables ....

i.e now the function is

void removeSfromString(char *str)
{
//no variable declaration here
}

Why? Is this likely to help the OP? If you want to offer a challenge, start a new thread, don't hijack someone else's thread

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

true has not been defined. Define it.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

So basically, no. All sizeof does is give you the size of the array, not the number of elements entered. You have to count as you insert.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I appreciate you comments on the code I am posting below....

Does it do what you want it to do? What kind of comments are you expecting?

And to prevent the :D's, use code tags. That will stop the :('s from happening.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

My concerns ...

Which forum would someone coding a game in C++ post?
Is it wise to create a development forum that is a mixture of all programming languages?

Game development isn't just about code in C and C++, it involves a lot of issues -- Artificial Intelligence Algorithms (generic algos), Game Play Ideas( like D & D RPG's ), Pathfinding related things, Talk about OpenGL and DirectX, etc. etc. (many others)

Concept wise Game developement is generic. Also it has come to my attention that some core members( Joeprogrammer, Mattevans, Niek etc.) are into game development courses and of course even I have done some work in that area (though not any more).

And because of this, the Game Development Board would IMO be geared not to 'coding problems' but higher level 'gaming concepts', whereas "I need help on my TicTacToe homework" is a C/C++ problem.

Of course, this will cause some consternation in new posters when they do need help with their TicTacToe homework because, as we all know, new useres rarely read anything except the title of a forum and rarely read all the way to the description.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I'm with Mr. ~s.o.s~ on this one.

Interesting. That's at least 3 that think your analysis does not help new programmers. What is it you understand that seasoned professionals (at least one of which has experience as a teacher) are missing? Especially being new yourself?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

No one has even said ANYTHING about disabling the start menu...In the mean time I have found out how to not allow a user to click it, but they can still use the windows key (on the keyboard to access it...I have already been accused of trying to make viruses on other sites, but I am actually trying to lock my computer from unwanted access (little brothers, sisters) So if anyone could tell me how to do it that would be wonderful.

You could set up a user password and log off the user when you don't want them to use the computer. That's why the OS has been designed with users. ;)

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Since only you know how the encryption works, we can only guess. And my guess is:
If your encryption changes a valid character to 0x1A, you get EOF in your file. To solve this, change your encrypted file to a binary file instead of text and that should solve your problem.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

so far i have written this but some how i think im doing it wrong if anyone could help thanks in advance.

cin.getline(players.name[SIZE];
cin.getline(players.name[index];

would work better ;)

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I'm beginning now to wonder of a possible mistake, as I draw out the pointer stuff again.

Since the char array was "She'll be a massless princess", we will have to eliminate the first 'S'.

With this code, I have *str = *p, in the second iteration of the while loop, I replace the 'S' with 'h'. That is right, and as we go on, we get "he'll ..." However, aren't I supposed to allocate a space (empty char) if I have a 'S' or 's'? In this case, I'm not having that ..

No, p and str are using the exact same space. You are therefore overwriting the bad characters in the string with characters further on in the string.

Another way to write the exact same code without pointers is:

i = 0;
    j = 0;
    while (str[j] != '\0') // '\0' is the string-terminator character
    {
        str[i] = str[j];
        j++;
 
        if (str[i] != 's' && str[i] != 'S')
        {
            i++;
        }
   }
   str[i] = str[j];

So j is pointing to the next character to move (str in original code), i is pointing to the location where that character is to go (p in original code).

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Its a graphical one, unfortunately.

So i need to do pixel programming , thas what i presume.

Is there a way to send the output as an image to printer through C(something done by printscrn.)

Ewwww :eek: Can't really help with that one, sorry.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Code is saved as an attached file to the post. See it?

Yeah, but I don't open attachments.... I practice safe computing ;)
But there still wasn't a question, nor an explanation of what was wrong.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

keywords = bold purple
comments = green
multi-line comments = italic green
characters and strings = blue
numbers = red
escape character (ie '\') = bold blue
brackets and parentheses = bold gray
everything else = black

I feel comments can be wrapped into one color/style.
escape chars are just chars, drop the bold. I don't feel bold is needed.

Possibilities:
Since strings/chars and numbers are essentially constants, make them both blue but different shades. Numbers in NavyBlue (#000080) so they stand out, chars in MediumBlue (#0000cd).
For "Everything Else", try Brown4 (#8b2323)

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

1: Take notes in class
2: Near test time, glance thru notes
3: If someone else is willing, pass info back and forth before test
4: Plan on opening the book up to the last day of class, then decide to forget it.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Firstly ... everyone keeps giving me different suggestions to color everything and confuses me!! Secondly ... that example doesn't highlight functions which would be the purpose of changing color to begin with.

Could you list the colors currently in use and for what? That might help come up with ideas. Are they defined as words or hex values?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Joe,

Cud u lemme knw whtz the difference between FPRINTF and FSPRINTF ???

I'm finding it difficult to read your posts ithe all the made-up words you seem to like. Please read the FAQ section called Keep It Clean

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I don't see a question, nor code. Please read the post at the top of the forum about homework...