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

Try formatting your code properly and I'm certain the error will jump out at you.

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

I'd add some output statements in key places after your 2nd input to see if it's continuing properly. Print out where in the code you are and some key values.

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

ummmmm...how? how do i use fscanf() for this?

I never suggested fscanf() . Use a command that can read an entire line.

how do i modify the second argument of fscanf(f,"%d,[^,],%[^n]",&n) so that it reads every value in a row till \n in different variables?

Don't bother. Use a command that can read the file easier and process the line yourself.

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

One for() loop with one printf() would be much easier.

And if you format your code we all could follow it better.

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

There's nothing specifically wrong whit this code that I can see. Are you attemptig to read a character somewhere else in the code?

This might give you a clue to the problem if so.

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

Assuming there are other lines in the file that have other tags at the beginning of the line, I would use getline() to read the entire line, then use stringstream to split it up into words. If you just use >> operator you won't know the difference between lines -- getline() will give you that control.

Unless you use getline() in conjunction with the >> operator as suggested.

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

Maybe you can point out about where you input is so we can find it? Asking us to look through 5 files and 300 lines of code is a little much, don't you think?

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

How exactly is this an obvious question?

Well-

How exactly do I turn these chars into numerical values? If it involves using ATOI/ITOA, can you please a very short example?

You answer your own question, and refused to look up how atoi works, asking us to teach you the simplest function.

Well thanks, but I need to convert to values ranging from 0 to 255. I also asked for an example, as I am not proficient with pointers.

Can't bother to try something. And can't bother to look up an example. You require us to hand-feed you.

But how do I pass it to this function? the type param is a char, not char *.

Another no-brainer. Don't define the value as a pointer.

If these aren't obvious questions, what is?

------------------

Who asked you to write my program for me?

Not directly, but every question you've asked you could have solved easily by looking it up. But you want us to supply an example (IOW, write the code)

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

Read each line
Convert the first value to integer.
Skip over characters until you find the ','
Convert the next value to integer.
Skip over characters until you find the ','
continue until done.

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

In programming, there is no "right way" to do most things. There's this way, and that way, and the other way. The one you choose depends on what you know and what you are doing.

In this case, after you open the file, you can use file >> label to read the label followed by some form of getline() to read the rest of the line.

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

So pass a char* instead of a char?

Are you going to keep asking obvious questions until we write your whole program for you?

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

However, out of curiousity regarding your above post, you're saying just pretend I have 25? Isn't the only reason that pretending I had 3 per line worked with fscanf because I had a constant format per line. There would always be 3 on each line, so it was easy enough to just go fscanf(myFile,"%d %d %d",&v1,&v2,&v3);

However, since I don't know the number of integers for each line, and only know that it COULD be up to 25, then how would I write an fscanf to do that? If I wrote %d 25 times inside it, wouldn't it continue to read the next line until it scanned 25 integers total?

Thanks

Loop. Done when you read the last number on the line.

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

plez?

gerard did help. It also might help it you read the Member Rules as asked when you signed up.

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

Where's the close that matches the open on 193?

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

Unless you can provide a citation, I'm skeptical.

Fine by me. As I said, "I have heard", not "he did"

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

Probably the most useful function available in C for this task is isalnum(). It will aid you extremely well in ignoring non-variable-name characters -- although watch for '_'.

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

Sit down at your desk and execute your code with paper and pencil. Be careful not to 'fix' the program in your head because you know what it should do. Do exactly what the code tells you to do.

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

I have heard that Knuth actually designed an algorithm that required a GOTO. It could not be removed using flow control. I don't know more than that, but I believe it was created in response to the "GOTO's are bad and unnecessary" movement -- just to be ornery.

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

I know printf prints to "stdout" how exactly

By definition on the standard. Beyond that, don't know, don't care. Just need to know that it works....

can I change the pointer to a class of mine that i'd prefer to handle the output string?

What pointer?

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

And yes, I do know the maximum size of values on a line, it shouldn't be over 25.

However, I'm still not sure how I would go about implementing your idea given this knowledge, could you give me a tip? Thanks.

Well, since you said

Pretend each line that starts with f only had 3 numbers per line,

maybe pretend they have 25.

t_man700 commented: Very helpful in answering my questions! +1
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Do you know the maximum number of values on a line? That would tell you how large to make the arrays of integers.

By the way, in your fscanf() , what does the %f do?

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

Probably doesn't work.

You're supposed to tell us what's wrong.

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

When you output the values, you've already incremented loopcounter past the values you just loaded... You're outputting garbage.

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

I left out some of the code that I wish to keep to myself. But I have isolated the problem and it seems as though while loop is never excecuting. This happened before I changed from while{} to do{}while as well. Any ideas why this isn't working?

It's working fine. But for all intents and purposes, it does nothing useful.

do
    {
        QueryPerformanceCounter(&timestop);
        int secondsleft=(minutes*60)-((timestart.QuadPart-timestop.QuadPart)/tickspersecond.QuadPart);
        char *message;
        sprintf(message, "%02i:%02i.%02i", secondsleft/3600, (secondsleft-((secondsleft/3600)*3600))/60, secondsleft-(((secondsleft-((secondsleft/3600)*3600))/60)*60)-((secondsleft/3600)*3600));
        counting=(secondsleft>=0);
    }while (counting);

All the work this loop does is destroyed as soon as the loop is finished because all the values are local to the loop only.

And your sprintf() is tromping on memory since there is no space allocated for the pointer message.

And if you are going to use (secondsleft>=0) to exit the loop, just use it to exit the loop. There is no need to hide it in a boolean variable.

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

We need a DaniWeb mascot that we can use in pictures like that,

How about these (third one's just for fun)

Dani commented: Haha love it +0
jonsca commented: Didn't you guys go to high school together? ;) +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

works for me.

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

You're welcome

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

Hmmm...

Nick Evan commented: Ha! +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Not getting a error it complies fine but as Waltp said my code is wrong because you cant do...
[snip]
the way i have it written. Any suggestions on how to fix it would be appreciated.

This should help

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

My psychic powers aren't working well. The problem I got was it made the coffee too bitter.

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

... my teacher does a lousy job of explaining things.

So do you.

C'mon, man! You changed code, right? Do we know what it looks like now? No!

You have a problem, right? Do we know what it is? No! All you said was "not what I was looking for". Response - Then make it give you what you're looking for. You are in control of the computer.

If that's not good enough, what might be some good things to tell us? What would your instructor ask if you said that? Well, assume we will ask the same questions and just give us the info. Don't make us ask -- it'll take days to fix a problem you should be able to fix in 10 minutes.

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

Hmm.. We're passing in an integer when it should be a pointer to an integer... In that case try changing the function prototypes and the beginning of the declarations to

void printStock (int v*, int n);
double Sales (int v*, int n, double cost);

He says he fixed all that.

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

Here's where I tell you to turn your brain back on and think. If you want to add values to a running total, where would you put that add?

Let's get away from the computer. Sit down with pencil and paper and run through the task. Write down the steps you take -- in order -- from beginning to end. Then look at the Then look at your code. Does it follow what you wrote down? If not, fix it.

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

When you use open a file in a function, you have to pass the file information (package_file) back to the calling function. You can't just create a file stream and read it, which is what you are doing.

OPEN: passes back the ostream
READ,WRITE,CLOSE: pass the ostream into the function.

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

Just call the function. There's no magic about it at all.

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

Look at the hint and rewrite your input functions first.

Where did you find the second code?

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

Find the '<', then find the '>'. Extract (copy) the substring between them.

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

Well, you can use the shell command to write the list into a file, then your program can read that file to retrieve the files.

Since I'm not familiar with a "find shell command". what OS are you using? When dealing with directories, that's an important piece of information.

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

Look carefully at the prototypes. Do they match the actual function? Do your calls match what the function is expecting?

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

And what is if (pos=str.find("<" && ">",pos+1)) supposed to do?

You said "My problem is it is not working right" which is fine but tells us absolutely nothing. So I waited with bated breath for what it was doing wrong. All I got was "it seems to be here". Please, when asking for help, also explain the problem.

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

What's your problem? It's not polite to make us guess.

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

Move your fac = 1; just before your factorial loop.

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

What do you know about reading directories in C?

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

See this. It's very enlightening.

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

I can see why.

He means that if you have VIIII, that's at the 5 level with more than 3 Is. You need to promote that group to the next level (5 -> 10) to IX.

IIII alone is the 1 level, promotes to V
VIIII is the 5 level, promotes to X
XIIII is back to the 1 level (X is not one step from I) so IIII promotes to V

Exact same pattern for XXXX and CCCC

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

I'd be willing to help if I could read your code. You need to format it so all of us can see what you are doing -- including you.

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

Well, the compiler is right. Where did you initialize yearsUntilRetirement? All you did is create the variable by that option, and no one knows what value is contains. The compiler is being helpful by pointing this out.

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

PLEASE HELP!

Don't shout. We can hear you!

I don't know what to do for main.cpp..

Function call that solve the problem.
Loops to go through the matrix...
IFs to test the return values from the calculation with the greatest sum found so far.
No file access at all: "All input data must be obtained from the stdin prompt."

I suggest you start with accepting the input and loading it into your matrix. Then output the matrix to be sure it was loaded properly. That and that alone.

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

That's right! And the OPEN, WRITE, and CLOSE can all be functions if you want. I would recommend the WRITE be one.

The append is an interesting but unnecessary solution. It means you must open and close the file for each and every write -- not very efficient. There are times when it's useful, but not here.