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

DON' CLICK ON THAT LINK. If you do, you will have to reboot your computer.:mad:

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

This is really a common problem of not asking the right question(s). I frequently see people ask "Do you know how to .... ", to which my answer is either "Yes" or "No". Afterall if someone is going to ask a yes-or-no question that is how I will answer. In your case you asked us if we would give you code to do something. That was the wrong question. You should have asked how to improve your code to make it do whatever you want it to do.

>>My original question was concerning a program that prompts the user for input
The algorithm for reversing a string is the same whether the string is from user input or a hard-coded string. Again, you may have asked the wrong question in your original post. Do you want to know how to get a string from the keyboard? Or how to reverse the string. ? Now I am not sure of your intent.

>My original question was concerning a program that prompts the user for input
you are quite right and everyone is encouraged to ask lots of questions. But you also need to ask the right question(s).


Anyway -- good luck with your program.

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

done -- happy to help.

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

you have to break the string apart and convert each part to an integer. There is no easy or quick solution to that problem because how to do it depends on the format of the string. If you are certain the string is in the format MMDDYYYY and the string is "02071984"

a[0].dd = atoi("07");
a[0].mm = atoi("02");
a[0].yy = atoi("1984");

Your only real problem is how to create the three strings "07", "02" and "1984" from the original string.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
int counter[] = {0};
for (int i = 0; i < 255; i++)
{
counter[letters[i] - 48]++;
cout << "LETTER - " << letters[i] << " APPEARS " << counter[i] << "TIMES\n";
}

array counter is not declared correctly. You have to tell it how many integers are in the array by putting a number between those two square bracket thingies.

int counter[255] = {0}

the loop counter should not go up to 255 because the loop counter is used as an index into character array letters and that array has at most 96 letters (could be fewer). So the loop counter must count from 0 to the number of characters in letters array.

<snip>
else
{
letters[k] = letters[k];
}

Above from function uppercase(). That is totally unnecessary, it is a do-nothing statement. You should just delete it (your compiler probably will delete it anyway).

for (k = 0; k < size; k++)
{
if (letters[k] >= 'A' && letters[k] <= 'Y')

{
answer[k] = letters[k] + 1;
}
else if (letters[k] == 'Z')
{
answer[k] = letters[k] - 25;
}
else if (letters[k] < 'A' || letters[k] > 'Z')
{
answer[k] = letters[k];
}

What is all that? First, letters array has already been converted to all upper-case, so there is no need to test for it here. Second, what is the purpose of array answer. If that was just for your own debugging you should have deleted it before posting -- and you …

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

I have seen that problem on occasion when using Norton Antivirus. And depending on the program you might have to disable a firewall that may be running on your ocmputer.

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

I may get grief from C++ afficianados but printf() makes it very easy to align data into columns. And it is C++.

No grief from me:eek: formatting text using printf() is a lot easier than with cout. I never could remember all thouse wiers functions such as setw().

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

It doesn't really matter what the file looks like -- how it appears on the screen is a function of the program that displays it. And different programs might display it differently. Font name and font size both influence greatly how the file will look on your monitor.

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

please post structure node. And use code tags -- see my signature for link.

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

Chaky: the file you posted doesn't work. After unzipping it, launched it. That brought un Microsoft Player and all I saw was message "Opening file". That cause 100% cpu usage! I had to turn off my computer and restart because I was not able to stop it. :mad:

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

Have any of you competed in the topcoder matches?

Nope.

Have you found them helpful?

Don't know, but I suspose they probably are.

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

probably want something like this. The function should return a const char*

const char* Stack:peek(void) const
{
    return topPtr->item;
}

// example calling 
Stack stack;
const char* item = stack.peek();
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>string s = a[pos];
should be the opposite
a[pos] = s;

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

>>Please, anyone verify this is the correct code?

compile and run it, then you will verify it for yourself. Debugging programs is 3/4th of the programming efforts.

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

No, that is not what you want. Re-read the requirements and the example in your original post

string h[6] = { "peter", "lois", "meg", "chris", "stewie", "brian" };
int k = insert(h, 3, "quagmire", 1, 6); // returns 1
// h is now "peter" "quagmire" "lois" "meg" "stewie" "brian"

first iteration:
h[3] = h[2]
h is now { "peter", "lois", "meg", "meg", "stewie", "brian" };
Notice that "cris" is lost -- tossed into the bit bucket

second loop iteration
h[2] = h[1]
h is not { "peter", "lois", "lois", "meg", "stewie", "brian" };

now insert the new string
h is not { "peter", "quagmire", "lois", "meg", "stewie", "brian" };

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

Glen Miller
Tommy Dorsey
Lawrence Welk
Elvis Presley
The Moody Blues
Janet Jackson

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
a[2] = a[3] <<< NO NO NO

NO! NO! NO! that is backwards. Look at the loop I posted.

a[3] = a[2]  <<First loop iteration
a[2] = a[1] << Second iteration 

a[1] = new string << final result

The loop counter MUST count down for this to work correctly.

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

I would use a different loop counter such as i to reduce confusion.

int i;
for( i = (n+pos-1); i > n; i--)
{
   a[i] = a[i-1];
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
a[n] = a[n-1];
         string temp = "";
         a[n] = temp;

That won't work -- yes it compiles but right after assigning the nth element the value of n-1 you turn around and assign an empty string to it. Delete the 2nd and 3d lines above, they are not necessary.

>>moving the n minus pos existing elements starting at pos one place to the right
That does not mean you move the entire array, only the (n-pos) number of elements. In the example you posted, n = 3 and pos = 1, so (n-pos) = 2, so you move "lois" and "meg" to the right one position, deleting "chris" in the process. All other string positions remain unchanged.

The loop counter needs to start at (n+pos-1), or 3 and count down (not up) to pos, or 1.

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

Hummmm -- why don't you just use CString's assignment operator? strcpy() is for C-style character arrays, not c++ classes. The code in that link is incorrect -- you can not pass CString to strcpy() like that. You will stumble across quite a few printing errors like that in books because if either carelessness or lack of good proofreading by the publishes, authors and proofreaders.

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

Here is an example -- claims to be Linux tutorial but will work for MS-DOS programs too. See item 4 (command line arguments) in the tutorial.

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

The loop appears to be about right except you need to save the value of pos so that you can use it after the loop finished. The current code destroys the value of pos.

Also, the else statement is unnecessary because of the previous return.

Remove the semicolon at the end of the function name/parameter list and add some brackets to enlose the function statements.

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

yes, length is the number of characters you want written to the screen.

If you do not have this already, here is a list of most common interrups

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

The keyboard and screen are treated just like files. There are three files that are always open when your program: stdin, stdout, and stderr are 0, 1, and 2, respectively. stdin is the keyboard, while stdout and stderr are the monitor. Here is more information about them.

int 21, 40h can be used because the monitor is treated just like a file.

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

I just want to ask how to reach the position which I want

Just repeat the code Bench posted until you get to the desired line. You will have to use a loop and a counter integer to keep track of the line number that was just read. If you are confused about loops -- which is understandable -- you should read about them in your text book.

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

Does anyone have a solution to the problem with the above program using the assembly language from Kip Irvine's Book?

Ancient Dragon,
I never asked anyone to hand code to me. .

Hummmm. But I'm glad you found the solution on your own. Now, would you mind posting it so we can all learn from it ?

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

Reading from a file works the same way as reading from any other istream, such as cin:

//read up to newline
std::string str;
std::getline(cin, str);
//read up to whitespace (after a word or character)
std::string str;
cin >> str;

With files, replace cin with the name of your ifstream

and just repeat that three times.

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

85 Implements
110 Functions

And no can opener :mrgreen:

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

I didnt ask you to write this program, I wrote it.

Yes you did and no one is trying to do it for you. I was attempting to make some constructive criticism to show better way of coding something. If you plan to write computer programs you might as well get used to that because you will encounter criticisms your entire career. Its called "peer review" and required by most companies that you will work for. you might as well get over being so defensive about other more experience programmers evaluating your code.

.And i thought i used the code tag because i highlighted the text and hit the code text button, which is what i was told to do.

I didn't say anything about code tags -- what you saw is in my signture and appears in every post I make. Yes you did use code tags correctly. :)

.the loop is needed so it will print all those titles again if someone wanted to enter another year again after the first time. otherwise it just prints the dates. I was just wondering if anybody new what could be used to loop printtitle with the main

you don't have to do anything. When printtitle() function returns the loop in main will take care of everything. The do loop in printtitle() is not needed.

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

the letters. The letters have to be reversed so that it can be compared to the normal line.

Good -- that simplifies the program. See my previous post. The rest you will have to figure out because I don't want to write your program for you.

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

do you have to reverse just the words?
"Hello World" becomes "World Hello"

or reverse all the letters? Reversing the letters is easy -- reversing words becomes a little more complex. As I mentioned in my previous post, you need to create a second string and copy the characters to it in reverse order -- create a loop that starts at the end of the string and decrement instead of increment the loop counter. For example:

for(int i = inbuf.length()-1; i >= 0; --i)
{

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

what is the purpose of that do loop? Why not just remove it ? And you don't need that switch statement if you put the month names in an array of strings.

char *months[] = { "", "January","February", ... "December"}
cout<< months[monthnum] <<setw(20)<<year<<endl;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I hate boxed instant mashed potatoes -- I refuse to eat them and will not eat in any resturant that serves them. We always have the traditional Thanksgiving day dinner (turkey, mashed potatoes, sweet potatoes, green-bean casserole, cranberries, turkey pie) and I always gain about a ton during that week. Thanksgiving is an American celebration that was inherited from British Harvest Day celebration, which was originally a religious holiday.

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

This is a c++ program, why are you using c-style char arrays. Unless your instructore requires it you should probably be using std::string as input buffer.

You do loop is all wrong. Use a while loop instead for better control.

std::string inbuf;
while( getline(infile,inbuf) )
{
   // blabla
}

now all you have to do is creae another std::string object and copy the caracters backwards from inbuf into it.

John A commented: Good job, Ancient Dragon :) --joeprogrammer +3
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you have to replace MyArray with the name of the array you created in your program. I only posted an example of how to do it, and did not intend for you to just copy/paste it into your program without appropriate change.

you posted the function but you did not post main() or the function that calls bowlerNumber(), so I don't know the name of the array you need to pass.

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

You need to download the Windows Device Driver Kit Can't help with your driver because I have never written on either.

[edit]I see from reading that page you might be too late -- the DDK for Win98 is no longer supported or available from Microsoft. Unless I misread it, that DDK was removed Dec 2005. Looks like the only way you can get it anymore is to find someone with an old version of MSDN subscription. Maybe eBay will have it ?????[/edit]

Here is more information about that. Microsoft is probably trying to get everyone to upgrade to either Windows 2000, XP or Vista.

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

you have to give the arran a name

player = numPlayers(int MyArray[NUMPLAYERS]);

Yuuc! that is totally wrong. If you are calling the function all you have to do is put the name of the array there, not the array size

player = numPlayers(MyArray);

if (player < NUMPLAYERS)

you have to add the substript to he array

if (player[i] < NUMPLAYERS)
          {
                player[i] = i;
          }

return player;

The above will return a pointer to the array. You declared the function returns an integer. Either change the function prototype/preemble or change the return value.

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

you have to give the arran a name

player = numPlayers(int MyArray[NUMPLAYERS]);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Why?

Take the idot test and you will find out.

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

OMG I'm just a big :twisted: idot!

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

Code::Blocks for small projects .

Never heard of it. Is is just a fancy Notepad with syntax coloring, or does it actually have options to use your favorite compiler (similar to what Dev-C++ does) ?

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

>>Could u pls write a c progra for this

Ok, wrote it in about 30 minutes, but I'm not going to post my solution until you post yours (that works)

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

The problem is somewhere else. You should post the rest of your program. You should have declare array count like this:

int count[255] = {0}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

depends on the operating system. MS-Windows and *nix: you can not do that because the os will not permit it unless the address is one which you got from allocating memory using malloc().

in assembly just store the destination address in edi register, source address in esi register, number of bytes to copy in ecx, then rep movsb instruction. There are quite a few posts on this board that demonstrate this, like this one.

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

Does anyone have a solution to the problem with the above program using the assembly language from Kip Irvine's Book?

Nobody is going to just hand you the code. Use your head for something other than a hat rack and apply the code I posted to your problem. It can't be all that hard to do assuming they are both written with the same assembly language.

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

You made a little mistake with your link. No big deal just test it and U will understand :)

Thanks -- its corrected now.

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

Please read my signature and follow the link

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

Microsoft VC compilers are really intended for mediam to large projects. Yes it is pretty complicated to learn, but you can't beat its debugger, object browser, intellsense, and several other features.

With single-file programs you will be better off using a simpler IDE like Dev-C++, or a command-line compiler and Notepad. I don't really like *nix command-line compilers very well because you have to manually write the makefiles, which can be more complex than the program you are writing. I'm just starting to learn Eclipse for fedora 6, which appears to have many of the same features as the Microsoft VC IDE.

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

>>And, I can simply call this from within the program when needed, say from the area it originally was located?

As long as it only gets called ONCE. Every time it is called it will reseed the random number generator

mattyd commented: ty +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you posted the requirements, you posted the code. Now, please edit your post to use code tags so that we do not go blind trying to read all that unformatted code.

>>I dont really understand what to do next... to match the sample output of this;
I think you were told you may not get exactly the same output.