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

Why not $pragma once instead?

Do all compilers support it?

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

You can't define a function inside another function. Move it outside.

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

this game is between a player and computer can you
make it between two player please ?

That would be your job. If you have working code to begin with.

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

while(!ins.eof()) is probably your problem. This should explain your difficulty ( feof is identical to .eof )

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

You compile both .cpp files into your project. The linker will take care of the rest.

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

yes a=0 is required in that for loop, since the loop has to be executed only once.

I need help in reducing the code to 65 bytes, or if there is any other code.
Please help me.

Please stop begging. Posting to ask for help does not need a "help me" on every post. IMAO, it doesn't even need to be said at all. This is a help forum.

Since the loop must be executed only once, by definition it is not a loop and therefore can be removed, saving many more characters.

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

First of all, when asking a question, as always, explain exactly what the program does wrong. It's nice and extremely helpful to know the input and expected output as you posted, but "it doesn't print in any semblance of that" is not descriptive enough. For all we know, the output is:

Mary had a barely queen
it's 3.14159 inches in burblex

which shows something very wrong. Whereas if the output is

StudentAverageQuizzes110.010101021.020137.786947.38410QuizAverage=7.05.07.5

we know exactly what we're looking for.

As it is, I suspect you need to use the iomanip header file and some of the stuff in there like setw and it's brothers.

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

Of course. The Psychic Programming InterNetwork will get right on it.

The problem is on line 36.

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

Are you still trying to open the file in argv[1]? If so, why? Your file name is in hFilename[].

I meant vector, which is actually what the 'v' part of argv is short for... :-)

OK, I can see that. I personally prefer using C/C++ terms for programming concepts rather than math terms when talking about programming. Less confusion. But that's just me.

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

As of right now, I'm simply just trying to sort PPG and return it to main. Then print the sorted array in main with the highest PPG first, and lowest last.

Then sort ppg. Don't waste your time
1- converting the ppg values into strings,
2- loading a bogus array, and
3- sort that array.

That should take care of your entire problem -- as posted.

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

First, we need to know exactly what error you're getting and where the error occurs. Don't leave it to us to read and understand all 181 lines of code -- pinpoint the problem for us.

And rubberman, argv is not a vector but an array of char* -- but you probably knew that...

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

That's because you sorted the array defined in your function (a). When the function returns, that array is gone.

What are you trying to accomplish? All this seems to be doing, assuming you get it to work, is sort the ppg of all the players, assigning the lowest ppg to the first player and the highest to the last player. They would no longer have any bearing on the players that originally had the value.

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

If the files are in fact identical, wouldn't they be identical 100 bytes at a time? And if you use the proper inputs, you will know exactly how many bytes were read, so your 45 byte problem isn't a problem.

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

use cout 's to follow your program:

Is your input completely correct? Display what you read and verify it's accurate.

Is your sort testing the correct values? Again, display what you are testing and at least whether or not the values get swapped. You probably don't need to display each value being swapped, just that you're swapping.

Watch for an unexpected value, like going through a loop too many times, or not enough times.

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

Hello All:

Hello you...

I searched through the old posts, but could not find an answer as how to read numbers from a sequential text file & calculate the average of the numbers.

Then you would have seen you need to post code pointing out your immediate problem. And use CODE Tags.

Do you place the calculation to find the averages outside of the loop to read the text file? If so, how do you transfer the number total outside of the loop?

How many times do you normally calculate the actual average of 25 numbers? That's the calculation itself.

If it is inside the loop, how do you add all the numbers (in this case 25 numbers) together before averaging?

The last part of this question seems to answer the previous question, does it not?

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

:$ no :icon_redface: sorry

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

It's a simple error to do. But without your code set up properly, you can't replicate it. And since we can't see your code, it's hard to help.

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

After you read an integer (12) you still have the ENTER in the buffer (you did press ENTER, didn't you?) After reading integers, you need to clear the input buffer before reading strings and characters.

There is a sticky post that discusses this at the top of the forum.

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

Sure there are other ways that are more complex and confusing. But why not just do the simple way. It's maintainable and understandable.

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

So what you posted is exactly the file you are trying to read? Something tells me no. Interesting, but overall useless.

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

Sure. It's called an input command, like fgets()

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

Do you have:
a design of the game?
inputs from the user figured out?
your snake designed and what it does? and how?
a gameboard figured out?

After 3 weeks, I would guess the answer is no.
So far we've seen absolutely nothing from you in answer to any suggestions we've made.

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

So why not post the most important part of the project -- the input file. If it's binary, we have one set of answers. If it's text we have another set. It helps to have all the info and a complete description. As it is, the description is spread over 3 posts and hidden in the code.

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

Not fixed yet.

In the C++ forum, the thread Moved: Database recommendation had the purple NEW icon when I logged in.

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

thank you!

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

I don't see any attempt at trying to make a function. Give it a try, format your code, and repost with CODE tags so we can help you.

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

I need suggestions on how to count the words, letters, characters on a file . I created a program of it however, when i use the "seekp(0L,ios::beg);", it doesn't go to the beginning. I want to just close and re-open the file but I think there is a better way than that.

Why would there be a better way? Just close and open.

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

Version 1, 2, 3, 4, or 5? Have your tried this?

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

Look up the FORMAT function.

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

How many bits do you want to test?

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

Anyone have an idea...

Sure.
Check the last bit, if 1, increment a count
Shift the value 1 bit >
Check again
Continue until done.

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

Umm, cout << letter; maybe?

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

okay, well i figured it out that it just needed setw()

it's basically,
i have a txt file
"HEY 10001011 10000111"
and i need to take each of the 3 parts and input them. So far, i have the "hey" and the "first binary" stored into an array, how do i store the second? would it be another binary int?

Exactly the same as the first. Why would it be different?

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

You're right. We don't know. You're point is...?

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

gracias...
ciao.

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

Did it work when you tried it?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
49: 		while (*name)
			printf("%c",*name++);

Not that good....

while (*name)
    putchar(*name++);

Much better....

Why use all the overhead of printf() when putchar() is perfectly designed for the task?

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

Use the function instr() to find the COLON. Store that position in variable C1

Starting at C1 test each character backwards (from C1 to 1) looking for the SPACE. Store that location in S1

Starting at C1 test each character forwards (from C1 to end) looking for the SPACE. Store that location in S2

Book is in 1 to S1-1
Chap is in S1+1 to C1-1
Vers is in C1+1 to S2-1
Text is in S2+1 to end

Use the mid() function to test each character and to extract the parts.

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

A READ followed by an IF using strcmp()

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

Purple icons are clickable to get to the first unread post.
When a post is moved, the purple NEW icon is displayed. It is not clickable.
Not being clickable but purple causes problems when it is clicked.

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

What would be a good way of using a buffer? the idea has always confused me slightly.

Start by defining a need for the buffer. If you need a character, you don't need a buffer.

It also depends on what you mean by buffer. I'm not sure of your definition, but it doesn't seem to be what most of us would call a buffer.

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

Since I can't read your code because of the lack of formatting I'll just give you a generic idea using

An integer array of 13 numbers: 3, 4, 5, 3, 2, 1, 3, 4, 5, 3, 2, 3, 5
An integer array of 5 counts intialized to all 0.

counts[numbers[i]]++; // increment the count for number[i]

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

When a post is moved, could you please change the post icon from the purple new to the grey nothing immediately? Leaving it a purple new causes problems as we click on the 'new' icon, since that's what we see.

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

Yup that's the problem please help me

Then explain in detail and post code.

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

My question is why are you using dynamic memory to create a pointer then a single character? Unless this is a required part of an assignment, it's ludicrous.

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

setw(x) -- Sets the number of characters (x) to be used as the field width for the next insertion operation.

It does not output x spaces. How many characters in total do you want the payee to output? Put that number in x. If you choose 20 and payee has 10, you will get 10 spaces + the payee.

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

I've tried to google the syntax for setw, but neither my book or the internet sources I looked at have led me to correct formatting. There is more to this program, but i'm just trying to get an idea for setw.

This search gives the correct formatting for setw . Don't know what you were searching for...

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

"The error" is certainly descriptive. Maybe "the problem" needs to be fixed.

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

Whoops missed that semi, good catch

didnt think I needed to add the type def in...

typedef unsigned char BYTE;

OK...

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

someFunc(ptrToArray); By the way, there is no BYTE in C