Consider this loop:
for (i = 0; i < 5000; i++)
{
sprintf(ifile, "file%04d.dat", i);
sprintf(ofile, "output%04d.dat", i);
//process the files
}
Look up the pieces of this code to understand what is happening.
Consider this loop:
for (i = 0; i < 5000; i++)
{
sprintf(ifile, "file%04d.dat", i);
sprintf(ofile, "output%04d.dat", i);
//process the files
}
Look up the pieces of this code to understand what is happening.
Although not a solution for Daniweb, there's a program called Flashmute that works quite well. It will filter all sounds from the internet while allowing local sounds to the speaker.
This program works everywhere. Now as I surf, I don't get talking ads, background music, and automatic videos interrupting the audio from my stereo, TV, or discussions with my wife I'm half-listening to.
Are you building the programs as Windows application or console app? I've had no trouble with BGI on XP when built for console.
This has been answered so many times in this thread -- why are you still asking it?
Write to Stroustrup and ask him since none of the answers here seem to be acceptable and his book is causing your meltdown. His home page is http://www.research.att.com/~bs/ with an email address at the bottom.
Is that a reason to avoid using the
const
keyword? I don't think so ...
Never said so. I was not commenting on const
vs. #define
. It was the enum/#define
comment that prompted my response -- and the silly keystroke comment therein..
Saving keystrokes is the worst reason. That way you get statements like x1=-b+(sqrt((b*b)-(4*a*c))/(2*a));
rather than x1 = -b + ( sqrt( (b*b) - (4*a*c) ) / (2*a) );
and are prone to make parenthetical mistakes at the very least and write other indecipherable code.
AAMOF I find it faster to do the #defines because of cut/paste. It takes 13 keystrokes for me to get
#define
#define
#define
#define
#define
Then add the definitions from the bottom up. Much faster.
Hence,
In the context of these loop definitions, they [[I]condition/expression[/I]] are interchangeable
Here's a perfectly good if statement:
if ((2*x)+7)
{
...
}
Is this considered a condition or expression? As I say, stop getting hung up on vague definitions of words.
IMO, you're getting hung up on definitions. Use a conditional expression in a loop definition and you've got a proper statement. As you get farther along, you can worry about the nuances of this conditional.
... what the difference is between condition and expression in these statements?
None. The condition simply evaluates to a TRUE/FALSE. Expression is a statement that will evaluate to a TRUE/FALSE. In the context of these loop definitions, they are interchangeable, and probably 'conditional expression' is more accurate.
[edit]Wow, a plethora of responses! We have no lives... :) [/edit]
I'm developing in c++ but yet need to use FILE * from c
Why?
1) What if my line is over 1024 chars????????? how should I fix my code to handle that situstion
If there is no '\n' at the end of the buffer you only got part of the line. This is one reason using string
and getline()
from C++ is better. Also in your code you never defined space for the input. All you did was define a pointer to who-knows-where and the first read will overwrite memory.
2)Do I need all these checks feof + size + fgets
No. Just check the return value from fgets()
.
3) if I want to use fgets but do not want to use char* line what c++ type can I use and yet use fgets ()with any convertion probably
Nothing. fgets()
only works with C-strings. At least not without unnecessary convolutions to use the wrong functions on mismatched variable types. It's like even though you have a perfectly good water glass next to you, you decide you want to take a drink by folding a piece of paper into a vessel.
We are not a homework writing service. Read the rules and start over.
Why are you guys still trying to help someone who posted
Beautiful. Thank you so much!
He got his answer!
Actually, FC did not bump a really old thead. NetworkExpert did. He just tried to help out what he saw was a current thread.
>i hope i did tag right on code posted.
Alas, correct tags are:
[code=cplusplus] source[/code]
But you did get the CODE tags correct. The cplusplus
part is optional.
Also, the PREVIEW
button would show you if the tags are correct.
How would i clear the buffer? Can i use the call cin.ignore('/n')?
Did you try it? What happened?
Thanks for the advice so far but it stll doesn't seem to be working.
I have tried the code in the previous post & that doesn't work.
---
This code here I made should terminate whenever it finds a number in Array A that does not occur in Array B but doesn't quite seem to be working?
Why does everyone leave it to us to figure out what your code does wrong? Can't you describe what makes you think it's wrong? When you take a car in to get fixed you never just say "it doesn't work", you describe the problem!!! :icon_rolleyes:
Just use paper and pencil to run through the code. Define A
to contain 3,5,7,9. Define B
to contain 3,5,4,6. What happens when i=0
and j
starts at 0 until the comparison is true?
Then go to i=1
, etc.
Yes, I admit that there are a lot of loopholes in the program given but it solves the purpose for alphaeis............
But what we like to do here is help them solve their own problems, not hand them a solution. After all, you don't get their grade. Therefore, it doesn't "solve the purpose for alphaeis", which is learning to do for himself.
Asking these questions aren't difficult enough.........
Anyway here's the answer.........for <fstream.h>
http://www.cplusplus.com/reference/iostream/fstream/and for <conio.h>
it's compiler dependent..............
It's console input and output header file.......which is quite different from <stdio.h> which is a standard header file.
The questions were not asked to have you prove you know what the statements do, but to ask why you used them if you didn't need them and why you didn't use any obvious error processing.
Then, for the 2D Array, you can use a double pointer..........then size constraint disappears.
No it doesn't. If all you define are double pointers you have no storage space, and a guaranteed problem.
I hope not. Seems to Big Brotherish to me...
So any improvements ?
Yes. Stop using TABs to indent. Set your editor to use 4 SPACEs when the TAB key is pressed.
As for exiting, you can exit when ENTER is pressed all by itself.
And about Ctrl+C, look it up.
The first 90% of a project takes the first 90% of the time to complete. The last 10% takes the other 90% of the time.
Of course, being a magician...
Is time travel possible?
up --> (careful here...)
Oh yeah:
up --> above
You don't care about the girls? :icon_smile:
Problem 1:
Add 14 to days.
If days > days-per-month
set days to days - days-per-month
increment month
This is the idea, which isn't complete. You can flesh it out.
Problem 2:
First output the number of elements in the structure (active people/books). 1 integer.
Then set up a loop to output each element of the structure.
Reverse it for the read.
Other option is to simply output the entire structure in one output command.
... but the problem is that when my data get bigger(i.e. more than 100 words) my program does a partial sorting on'em and it does not print the file in the end at all.. and i think it gets into an infinite loop cuz it does not end successfully
...cuz i'm almost sure that my program is bug-free
Two statements that can't possibly be true. And both in the same paragraph!
Definitions:
bug-free - program runs with no problem and outputs the correct information each and every time.
buggy - the program doesn't work for at least a certain set of data.
....... so i'm really astonished why!!
Because you need a reality check :icon_wink:
I just double-click on the executable or I run it from VS if I have just modified some line..
Those two ways will generally give different results.
Give us more data and we can give you a complete answer.
LoL, my mobile phone has a C++ compiler running on DosBox.
Jeez :icon_rolleyes:
:)
You must have missed the 'OR' part of the post #3.
You must have missed the smiley to show you were kidding. Reread post #3 through the eyes of an extremely new (albeit lazy) student. What's it say to you then?
First thing you need to do is rethink the YEAR loop. Make it shorter. The leap year section in it makes the loop too complicated, and it's wrong. Don't deal with LY as a full year, it's one day.
Start with that.
i'm just wondering, "where's the love?"
Good question. And from the person that posted:
I'm just sayin' :icon_wink:
The God has sent me to say "C++ compiler is not a pocket calculator."
Then why did he package the computer with the program calc.exe? It seems he does -- if you have a pocket big enough! :icon_twisted:
He's counting his digits from right to left Walt.
So IMHO it has to be more something like this : (pseudocode)number = 12345;
n = 4; //we seek the fourth digit from the right
num = number / 10^(n-1);
digitvalue = num % 10; //this we want
Interesting....
Dividing by 10, Mod'ing by 10. You just added the obvious power which was hers to think through. I tried not to take all the thinking out of the problem.
You didn't tell us the most important thing about your program. What is happening to make you think it's weird?
For what I know, those to are equal...?
char *a = "aeiou";
char a[] = "aeiou";
In general terms, yes, they are equivalent. *a
is a pointer that points to the string a[]
is an array, and a
itself is the address to the string -- effectively a pointer.
Though not quite the same thing, at this level they are interchangable.
Yes, what's your point?
Simply to verify my thoughts on the subject.
Divide (/) by 10
Modulus (%) by 10
Narue,
Because fgets()
reads a line up to the \n and loads everything up to the RETURN, isn't it simply a matter of testing the last character in the buffer with \n and if it isn't, they entered more than the requested data? Simple use of strlen()
and a test?
After reading in the password call functions to test each individual rule. Don't try to test all things in one function, or ghod forbid right after the read.
Yes it is.
It's perfectly acceptable to compare floats. You just have to understand the difficulties and know how to deal with them.
Because floating point is not exact, you need to define what precision is acceptable. If you want a .01 variance, simply test for it:
if ((inputValue > targetVal - 0.01) &&
(inputValue < targetVal + 0.01))
{
Now if you input 5.0 and you get 5.00000001 your comparison works fine.
If you are asking about ways you can improve it, if you look at itoa, it needs to be able to handle negative numbers and it needs to be able to handle different bases:
char * itoa ( int value, char * str, int base );
Agree with negative, disagree with base. Since it is a compiler-specific function, there is no 'official' definition. Therefore, adding base is simply a possible feature/addition. :icon_wink:
>>Dear NathanOliver, your code is working perfectly after changing..............
It may be working on your implementation but the code is in a state of undefined behavior.
How so?
>>Edit:: Some additional information on if (test != input) as 'input' is a double
>>and 'test' is an integer, 'test' will be implicitly converted to a double to do
>>comparison
This can't get worst. When you know he is doing a float comparison, there is a lot more need to warn him than smiling.
To OP and everyone : Never use float comparison in your programs. It will lead to undefined behavior.
You may want to like to read: http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.17
Unfortunately, you do not understand the term "undefined behavior". It has a specific definition. Do a search to learn that definition. What we have here is a "logic error". You will also note that the term "undefined behavior" does not appear in the link you posted at all.
When you finish reading a line, you are automatically ready to read the next line. So just start reading again and there you are!
Can't read the darn thing! Did you bother to read any of the requested information posted all over this site about CODE tags, like
1) in the Rules you were asked to read when you registered
2) in the text at the top of this forum
3) in the announcement at the top of this forum titled Please use BB Code and Inlinecode tags
4) in the sticky post above titled Read Me: Read This Before Posting
5) any place CODE tags were used, even in responses to your posts
6) Even on the background of the box you actually typed your message in
But, I checked it in a C++ Book(*) before I posted these examples ...
(*) C++ Beginner's Guide by Herb Schildt, a free legal ebook copy is available here, so you can check the
do-while
if you want (Chapter 11, p31-p33) ...
So ol' Herbie is wrong, legal book or not. Publishing bad information has been know to happen -- a lot.
But if you use a
do-while
statement, theeof() check
is always performed after the reading, so what's wrong with it ?
Yes, but you are processing bogus information before the eof() check
. Did you look at the link I posted? Write your do-while
loop and read the file described in that link. If it works, post it. If it doesn't, :icon_wink:
We are not psychic. When you take your car into the shop to get fixed, you need to give details to the mechanic so they have a clue what the problem might be. Same here.
Before posting you did read the sticky post at the top of the forum with the title Read Me: Read This Before Posting, didn't you?
No? Why not? Doesn't the title mean something?
Given that, another option is to have an array, one entry for each alarm.
Option 1:
When a value is received,
1) if array entry = 0
a) print the alarm
b) load 20 into the value
2) if array entry <> 0 decrement the array value
This way every 10 minutes the value becomes 0 and and printing will happen again. But when an alarm becomes inactive, you'll have to get a 'clear' signal and clear the value.
Option 2:
When a value is received,
1) if array entry = 0
a) print the alarm
b) load 20 into the value
2) Every 30 seconds, go through the array and decrement any values > 0.
This will automatically turn off any alarms that are no longer active.
If you really want to use a loop do something like this:
Your first and second examples are just as broken as most other loops using .eof()
. But if you combine the two:
string x;
infile>>x;
do
{
/* your other instructions here */
infile>>x;
} while (!infile.eof() );
Reading needs to be done immediately before the test with .eof()
. Try this explanation to see if you understand it better. ( feof()
is the same as .eof()
)
So what's wrong? The sample is doing exactly what the code says to do.
Read the rest of the current line.