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

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

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

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

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

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

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

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

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

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

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.

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

So why not
1) open the file before the loop
2) write the data to the file when you get it
3) close the file after the loop
:icon_question:

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

Is there anywhere in your problem description that states you must save each input somewhere?

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

Asking a question on a Forum does not give you the right to a perfectly coded answer to your question.

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

Some people post here looking for help. Others post to have their problems done for them.

We've given you help. 4 different suggestions and code.
You complained. You want us to write the code for you. Sorry. That's not how this public forum works.

If you want to post more information to help us understand what you don't understand, please do. But right now, I guess we don't really know what you need.

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

Sounds like your idea will work well. Try it and see.

I don't know about stopping at whitespace, but you can certainly find whitespace after your substring is found.

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

The only thing I did not see in this thread is:
Use the difftime() function check the time difference.


But what I do see is a lot of help given and no attempt, only attitude, from the person asking for help. Please reread this thread and try using the help given.

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

Look up the methods of the string class. There's a lot you can do with it.

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

Sorry, didn't remember there was a split command. Ignore my post

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

I use instr() , mid() , right() , and left()

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

You didn't pass your file pointer into fn_out() . You created another one which was destroyed when the function ended. Pass fp into your open function.

Also, see this about scanf() and this about fflush()

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

The time() function is not used by the rand() function. It's only a way to seed the srand() function with a different value every time it's called. rand() returns a value from 0 to RAND_MAX (32767 on many systems).

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

That's pretty much it, except
1) main() is an int, so always use int main() .
2) Watch your formatting. Be consistent.
This section

while ( i <= num )                  // factorial 
     {
           result *= i ;
           i++ ;
           }
         
         cout << num << " ! = " << result ;
         cin.get () ;
}

should be

while ( i <= num )                  // factorial 
    {
         result *= i ;
         i++ ;
    }
         
    cout << num << " ! = " << result ;
    cin.get () ;
}

You are using SPACEs to indent -- excellent!! Switch to 4 though, not 5.

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

Since your nodes don't store the parent, about the only thing you can do is read all the nodes and look for your current node in the children pointers.

IMO, you need to modify your node structure to add the parent node since you are traversing up the tree.

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

1) Give your variables useful names. var1 could be gallons of milk for all we know.
2) What does the input file actually look like?
3) Maybe whatever value it outputs is exactly what's in the file.
4) Since you have no error checking, maybe the file can't be found, file is locked, etc, when you tried to open it.

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

OPEN a file
WRITE or PRINT the data
CLOSE the file.

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

Depends on what "red line" means. We can't even hazzard a guess without more information. Like maybe an error message.

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

Hey everyone :) Hope you can help

Here is what I've done with the instructions given:

I need to know the average price difference between the cash and credit prices. But i'm pretty sure that only comes in at the end. Here is what my this function is supposed to do:
determine the difference between the cash price and credit price for an item and add this difference to the total of the differences. So what I've done below seems pretty basic to me- but I'm guessing this must be the error based on what I try to do with the code later on.]

Yes it seems pretty basic.
I suppose it could be the error, if we had a clue what the error is. Without explanation of any kind, I can see either no error, or a possible error. But I'm only guessing.

When asking for help, assume we know nothing about your code, and your thoughts on the program. You need to explain in detail what you are trying to accomplish, and what leads you to believe there's an error.

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

Think about it...

How do you add 2, then 3 to get the values you want?

x = x + 2;
x = x + 3;

Where would you add 2, then 3 in your program?

Don't you have a FOR Loop in your program? What does it do?

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

that my code, im having trouble with the counting letters and words part, any suggestions??

Sure. Explain why you think it's not counting words and letters.

also im not even getting an output, but thats probably sometihng minor with the last function?

You're calling the output function. What makes you think it's not giving any output?


When asking for help, it's important to also give the details explaining what is (or isn't) happening. Not just "Broke, why?"

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

How do you add 2, then 3 to get the values you want? Where would you add 2, then 3 in your program?

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

By the way, isalpha() only checks for Letters, isalnum() checks for Letters and Digits..

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

You actually don't need vbscript to do this. Go to a DOS prompt and type

dir /?

That will show you how to get a list of all the things you need. Try this:

dir *.jp* /s /b > myfiles.txt

This will give you a list of all files (with directory information!) that have .jp* extension (e.g. .jpg, jpeg) and store it in a text file. You can then use a good text editor to add a del statement to each line, or to remove lines if you don't want to delete the files in question. Kind of old-school, I know, but if it's a one-time task, why spend the time to learn a new language?

I agree. But this won't work with hidden folders. But then again, if they are hidden folders, you wouldn't have pictures in them, would you?

Alternatively, look at ZTREE. It will allow you do do exactly what you need with little fuss.

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

m a bit confused...how can it b written in C coz again u will need a C compiler to compile it..

Yeah, so? You compile C-version-6 with the compiler C-version-5 and you have an updated compiler.

also if it is written in assembly..then how can the code run on different machines..i mean,assembly language would be different for different architectures,won't it..??

If only standard C is written, the source can be built on different systems which makes them run on the architecture built on. For those things that are architecturally specific, like I/O, different code is written for each architecture.

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

Also in assembly.

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

It is obvious to me that common decency is far beyond your level.

Common decency? I gave you an answer that will work extremely well. You ignored it.

Can you explain the code from L7Sqr? If so, you should know why didn't it work? If not, that's why it didn't work. Has nothing to do with common decency.

Look at your post:

Thank You, this code works for me but when I try and sub the lastLine I get from my code in place of your s it does not work? Why is this?

Common decency dictates you explain what happened, not force us to use psychic powers to figure out what you did wrong. Show us.

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

Thank You, this code works for me but when I try and sub the lastLine I get from my code in place of your s it does not work? Why is this?

Probably because you tried to add code you don't understand and expect it to work without modification. It's obvious from the code you posted L7Sqr's code is far beyond your level.

JordanHam commented: Rude +0
debasisdas commented: harsh reality +8
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You need to parse the line. Find each (,) and
1) Convert the value to float and store it.
2) Search for a comma
3) If found, skip over it and go back to 1

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

i am genius :P hahaha i found out :P

i should really start using algorithms first and not going straight to compiler :D

Yes you are a genius. Most students have to be told to do the desk work first. Now you see how important it is. Congrats!

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

Couldn't you mod by 10 then 100 then 1000 and you would get the ones, tens, hundredths, thousandths that way?

No. 128 mod 100 = 28, not 2.

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

After you get the ones digit, divide the number by 10. Now the tens digit is ready for the %.

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

Create an 'input form' that looks like an InputBox. For every character hit, save it and replace it with '*' in the TextBox of the form.

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

In my system, which is ubuntu, fflush doesnt do anything. Ive tried using fflush(stdin) and it doesnt really flush anything, the characters in stdin are still there. fflush doesnt do anything in my system,its just like another empty line.

That's because the standard states fflush() is only required to work on output streams. It's not 'defined' for input streams, sayeth the standard. That doesn't mean a compiler can't implement fflush(stdin) , you just can't rely on it. And because of that, you shouldn't use it even if it IS defined. When you get used to using it on Windows, then you get to Ubuntu, suddenly nothing works.

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

On top of that, why must there be a rule written down before you won't do something? If multiple people say "don't do it", just don't do it. There is no specific law in my country that say's "when in a crowded movie theater, don't yell FIRE!" But if you do it, you will get arrested anyway.

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

Thank you fbody but i still can't see a rule resembling this restriction.It is addressed to those who post vague questions and ask for code without providing evidence of trying.Well this didn't happen in my posts but at the time when i first started posting .. i admit i didn't read the rules right away but now i was actually trying to abide them.What?Oh .. and where did you see Waltp.. frowns on stackoverflow.com where everybody is posting relevant pieces of code to actually help each other and not vague phrases lile "do this .. do that .. erm .. no no no try that instead".From your private message i understand this is your forum and your site i can play by your own rules which stem from your state of being .. (not being written anywhere) or "provide my great knowledge elsewhere".Is that really the politics on daniweb?Cause if so .. i will just delete my account (not sure if i'm allowed though)

Ahh, so now we're down to personal attacks, even though I've down-repped you once and others have been down-repping you since you started.

Read cscgal's statement again "please don't expect quick solutions to your homework." Read between the lines. Use the logic necessary in programming for more than programming. What's that statement say from the helping side of the post? Isn't posting full working code a quick solution? N'est-ce pas?

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

Posting code isn't the problem. It's the situation and type of code posted.

Read this.

Yes, as cscgal says:

Though we are all here to help, please don't expect quick solutions to your homework. We'll help you get started, exchange algorithm ideas, how-to's, etc. but only if you show that you're willing to put in effort as well.

So, to the question "Can anyone tell me what am i missing?", it's listening to long-time members, moderators, etc. and doing your own thing against their recommendations.

And consider yourself lucky. This thread is in direct violation of the Keep it Organized rule "Do read the forum description to ensure it is is relevant for your posting". This post does not belong in the C++ forum. So, if you really want to complain about rules...

And speaking of rules, the rules of English require a SPACE or two after punctuation. Don't know about your native language, but here the rule is "Do post in full-sentence English" (Keep it Clear). I think we've let that slide for over 200 posts, haven't we?

All we're asking is if someone suggests that you stop doing something, then stop.