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

i dont know how to explain this any better, without resorting to code. here it is 'explained' in pseudocode

first problem:

for i = 1 to CHARS
{
    for j = 1 to i
    {
        print "$"
    }
    print \newline
}

second problem:

for i = 1 to CHARS 
{
    for j = (CHARS - 1) to (CHARS - i) 
    {
         print char('A' + j)
    }
    print \newline
}

That's not pseudocode. That's BASIC. :icon_wink:

jephthah commented: going to look it up on wikipedia, now :P +6
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
if(!inQuiz)//if file did not open correctly
	{
		cerr <<"File could not be opened." <<endl;
		exit(1);
	}

There is no reason to call a function to exit from main() . Just return 0;

inQuiz.seekg(0);//set position to begining of file

When you open a file you are at the beginning of the file. No need to seek.

inQuiz.seekg(1 - 1, ios::cur);
	inQuiz.getline(answer, sizeof(answer));
	inQuiz.seekg(1 - (sizeof(answer)), ios::cur);

Again, why do you have to seek? You read the answers and the name is read next. It's automatic. Seeking is only necessary when moving non-linearly through a file. You are making file reading way too complicated.

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

5% doesn't mean anything in code.

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

Is it ok if I used this macro to flush the buffer?
#define FLUSH while(getchar() != '\n');

You could, but why? Just use the while line. Just make sure you haven't read it '\n' yet.

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

can anyone give me some hints on this im having issues

thanks

Biggest issue is not reading the rules and posting any information at all about what those issues are. We can answer specific questions, but if all you're going to do is talk in generalities, the only help we can give is writing it for you.

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

Please ignore fr3aky's poorly formatted unreadable code. It will teach you very little that is useful.

fr3aky, here we do not not give programs to people, we help them solve their own problems. And when we post code the help, the code is formatted, readable, and useful.

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

what do you think ?

The code is terrible.
1) Doesn't use a loop
2) Uses the dreaded goto 3) Inconsistent indentation

You get a D, and only for the effort.
But you fail for trying to do someone else's homework for them. Here we help them solve their own problems, we don't solve them ourselves and let him cheat.

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

getchar() doesn't read anything until you press the ENTER key. Then is starts reading from the first character entered. If you enter "XILWVMCDI", when the program reaches W the loop exits. "VMCDI" and the ENTER is still in the buffer. You need to clear the buffer before continuing or your next input will get the V. I'm sure that's why "it returns a zero for every character"

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

Post the code that shows how you constructed the contents of that path variable and argv[] array of strings.

Alright, well the program I'm trying to exec doesn't really need any arguments..so you can think of the arguments array as being:
char **arguments_array = {program_name, NULL};

and the path is the following:
char *path = "/path/to/program";

Now, the 'program', which I'm trying to exec, would normally reside in the current working directory. When I call exec with the path being just the program name (i.e. : char *path = "program_name";), the exec call seems to find the program and runs perfectly. It's only when I add the '/' (backslash), that's when the exec produces the "Directory or File not found" message...

Did I miss the code somewhere? Is it in another thread? Or did you completely ignore what AD asked for?

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

After you test for EOF, test for an invalid character. If you got one, clear the rest of the input buffer and return 0.

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

Reading again after you already reached the end of the file.

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

Last night's pizza! Yummmmmm.

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

Do you have to deal with each value from 0 to 255 for each color?

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

Input the operation before the do . Then just before the while input the next operation.

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

Random number mean that it changes value. The position is the same.
Did you wanted to change position or value?

Not necessarily. It simply means you cannot predict the next value -- which in fact may be the same as the current value.

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

He called you a turabo.

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

Looks like your two hour time limit is going to approach fast. Maybe you should have figured out how to program rather than wasting your time writing this up for cheating.

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

Then that spot wasn't the problem. You might have to resort to the debugger.

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

And we're supposed to magically figure out which of the 283 lines might be your problem?

I am trying to get my school program on pointer variable linked lists to work, but I have incountered a runtime error.

Bummer. Since there are quite a few runtime errors, is there a particular one you're interested in?

When I try to print my data to the screen or a file, it does not work.

Like it prints the Declaration of Independence instead? Or prints garbage?

I am not sure if my program is not reading correctly, or just not printing.

There are very simple ways you can use to decide if it's a reading problem. After you read, display what is read...

I know I sound annoyed but posting 283 lines of code with no real explanation (details) of the problem, nor any direction where to look, is not helpful.

You seem bright enough to know that since we didn't write the code nor can we see your screen, you've given us nothing to work with. What's the first thing your mechanic asks when you tell him "my car won't work?" Same thing with programming....

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

Your first problem is that

Like I said most of it is still half written and Im still fidgitting with it.

Stop fidgitting with it. Take one task, write it. Test it. Perfect it. Then move to the next task.

I'd recommend starting with the display function. Write it completely first -- passing parameters so you can display either player's board.

Then write the ship placement function. Takes board, ship, starting position, and either the direction (up, left,...) or ending position.

Now the user input function, which calls the perfected ship placement function. Then modify the user input function to create the computer 'input' function.

Etc....

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
1.) system("PAUSE");
2.) system("PAUSE>NUL");

Neither are recommended... 3.) cin.ignore(2); Useless without cin.get() to read the character to enter.

Use a combination if cin.ignore followed by getline to pause your code.


By the way, software does not collapse. Please explain what you really see in detail otherwise all we are doing is guessing -- which is all these two posts are doing anyway.

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

Then every time you delete , set a to NULL as you did here. And every time you delete , if a is NULL, don't. There is no a to delete.

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

You think? "2" is not a number, it is a string that has a number in it. Double quotes define a string. Any character is allowed, including the characters '0' - '9' -- they are characters, not numbers. 0-9 are numbers. (note the quotes, that's makes all the difference.

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

Come on, people. The solution is much more basic than anything posted here. The solution is

Learn to format your code! This link (if followed properly) will eliminate most else problems, bracket/parenthesis problems, and misread code problems. It makes your code easier to read, understandable, and maintaining the code is a snap.

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

You apologize, but you don't bother to correct the situation. Like everyone else, I don't know what you need help with since you can't be bothered to explain it.

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

Did you read about strings like I mentioned? What else can I do for you. Write it myself, maybe?

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

If you know vectors, you certainly know how to read a string. If not, maybe you need to read your text about strings and input.

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

Thank you Guys!

fflush(stdin) is from output buffers, forces all data in the buffer to be written. that's why i still using.

Since when is stdin an output buffer? Where does it write to?

and my institute request to use CTurbo to finish this Project. im still stacked by same problem. please i hope you guys will help me :)

Sounds like you need to find an institute that will teach you programming... Real programming. Things have changed in the pas 30 years.

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

Read each word. Search for 'w' in the word. Pretty simple.

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

LOL!..its some assignment I have so not sure its a good thing to do posting my code...but from debugging this part of the code could potentially be the problem but still not sure..

char line[256];
FILE *fd = fopen("FILE.txt", "r");
while (1) {
        if (fgets(line, 256, fd) == NULL) {
                  break;
        } else {
                  // Do stuff...
        }

Did this happen to anyone?? or just me...

If FILE.txt does not exist, you continue into the read loop. Granted, based on this snippet, the if will error out, but still it's a bad practice.

And since we still don't really know what's happening, and you're not even sure if this code is the spot, we really can't help. We need details and code that exhibits the problem. Weed out everything you can until you're left with a short code segment that exhibits the error.

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

Sure. Line 235 is wrong. Don't use a pointer there....

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

Yes, I could do that. But it would be a lot easier only having 1 type to keep track of. Else I would have to check if it's 11 and create a new char/string and print that instead.

Not true. Just create a name string array available for all displays: string cardDisplay[] = {"Ace", "2", "3",...,"10","Jack"...}; then each and every time you display the card, use cardDisplay[card]

jonsca commented: Works too! +2
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

P.S. I dont want to use a cin.ignore() and cin.get() after one another as the double enter makes things sluggish and clunky feeling.

Yes you do. cin.ignore is not an input, it clears the buffer. Then to make it wait, you use the cin.get .

But, as firstPerson mentioned, getline would be better. cin.get only gets the 1st character, and if the user types anything more than ENTER, you've still got a problem. getline solves that problem.

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

Usually, I'd tell you fflush(stdin) is wrong. But since you are using a thirty year old compiler with functions that haven't existed since the mid-80's, I'll let it go this time. I hope you aren't learning on this compiler for a potential career. You will have to unlearn a great deal. cprintf() is the Turbo graphics version of printf()

Salem commented: Wow, you made it through nearly 1K lines of TurboCrap +19
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I just decided to call the post as it was... I guess it caught on.

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

Sure. Write some code, try to do what you are asked to do. And if it doesn't work, post it here and explain as much as you can about what you did and what went wrong. Don't forget to follow the Member Rules.

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

Read? Sound like from a file or user input. Or do you mean get the time from the system?

I really don't see the need to get both separately. Get them together and move the DATE into the date variable, move the TIME into the time variable.

I'm actually not sure if there are separate functions.

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

Start by writing some code that outputs each word.

Then change the code to add capitalization.

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

Move each character after the '0' one location down the array.

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

I assume your question is still sorting? I don't see any attempt so it's hard to know what you're having trouble with.

Start with a basic pencil & paper solution.
Write down these numbers.
5, 32, 12, 8
Step by step, how do you sort them if they were on a math assignment?

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

Don't know what it means. Tell us.

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

Why google for something they don't believe is a problem? Just because someone says don't is not enough of a reason.

Just sayin' :icon_wink:

And if that's why I'm here, why post at all if I'm just gonna have to clean up after you? I don't even clean up after my kids, and you're old enough to know better :icon_twisted:

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

What I would do is whether you find a solution or not, just keep looking.

IOW, when you find the first solution, save it in a file. Then just continue looking as if you didn't find a solution. Eventually, you should find them all.

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

Just out of curiosity, why is it important where?

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

You are the one that will need a lot of luck if you think it is acceptable to make use of fflush(stdin) and gets().
fflush() is undefined if you give it stdin as an argument.
gets() is not an option even for throw away code.
It would be better if you do not touch the keyboard at that point.

In other words, gets() and fflush().

It's good to give an explanation, not just tell people something and they just have to believe you. None of us have credibility to new posters.

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

Of course you can access a CD drive with C. Floppy, too. If you're having trouble with a floppy, you're probably just doing it wrong.

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

Read the input as a string and test each character to make sure it's in the proper format nn:nn . Then convert the numbers.