No. All (normal) messages go to a window event handler.

The functions you write to handle events can, of course, be as window agnostic as you like.

commented: thanks +3

stty is not the best option for this.

You should first look to see if the environment variable $COLUMNS exists. It is most likely to be correct.

Failing that, use the command tput cols to query the terminal size.

If you really want to do it properly though you'll have to use ioctl() with TIOCGWINSZ.

Hope this helps.

Apple is putting a lot of effort into LLVM. Unfortunately, the LLVM debugger doesn't work with FPC (yet, AFAIK).

You'll either have to get an old copy of the GDB or install an older version of X-Code (you can do this side-by-side with your current version).

Alas, I don't have access to a Mac and I don't know any better than this. I just noticed that no one has answered your question...

Hope this helps.

It is not egotistic to simply respond to having one's [i]very simple[/i] code roundly abused. The function has the performance and memory characteristics desired when I wrote it. It has no leaks. It does what it is supposed to do. And it isn't filled with convoluted, non-standard stuff.

I've responded to the syntax error you have actually shown me by correcting it, but you have yet to respond by showing exactly how my function has a "logic error" or what all these unnamed "bug"s are. Instead you have resorted to [i]ad homenim[/i] by personally belittling my understanding, experience, imagination, and behavior.

Bye.

[quote=Narue]Looks like a bug to me. Addition of pointers is both nonsensical and illegal in C. I see what the author was going for, but it seems especially awkward. I'd rather just keep a running count of the string length and set [inlinecode]block[/inlinecode] to the current null character on each iteration. It's much simpler that way:[/quote]
[quote=Narue]You're correct. While addition of pointers is illegal, even if you fixed it, there's still a logic error in that line.[/quote]
Pointer arithmetic is [i]not[/i] illegal. What is illegal is to perform arithmetic on [i]unrelated[/i] pieces of memory. The pointer arithmetic was not a mistake; however I could have been more careful to code it as:
[code] block = ok + (size_t)(block - result) - 1;[/code]
Since you are in to giving a code review, I'd sure like to know exactly what the logic error is in that line. It seemed me some pretty simple addition for me that kind of error.

Also, I don't think that there is any point in keeping an extra variable around to track information that is already available in [inlinecode](block - result)[/inlinecode]. If I were developing under some specific company guidelines that addressed stuff like that I could easily adjust to do just as you would. Otherwise it comes down to nothing more than simple, personal preference.

[quote=vedro-compota]as i see - this original auther code won't work at all (even without bug about which line we spoke earlier ...[/quote]
Those are pretty careless statements to make, considering you ...

commented: + +3

[URL="

commented: ++++++++++++++++ +3

Your professor has actually given you a complete solution -- but his pseudocode is a bit off.

Your function should take only one argument: [b]v[/b] - the value to convert to base 3.

Everywhere you see "b" in his pseudocode you should replace that with "3" (because "b" is the [i]base[/i] -- your base is [i]3[/i]). (You could, if you desire, add a second argument to the function: [b]b[/b], and use that as the base, then call the function with a base of 3. It is trivial to make the function work either way.)

Inside the function, the first thing you should do (as you have) is calculate [b]k[/b]. You have used the second form the professor gave you, since there isn't any [b]log3[/b]() function in the standard library. Remember that the logarithm to any arbitrary base "b" can be calculated by dividing the logarithms using another base (for example, base 10) as:
[tex]{\bf log}{3}( v ) = \frac{{\bf log}{10}( v )}{{\bf log}_{10}( 3 )}[/tex]

The number [b]k[/b] represents the number of digits in the output. Your professor's algorithm uses it to select the bits out of the argument [b]v[/b] that are to be printed - most significant to least significant. Most numbers have more than one digit, so you will need to loop through them:

[code]for (; k != 0; k--)[/code]

(His pseudocode was not very careful to indicate that there is a loop in there... but if you think about it you will see it is necessary. Step ...

What version of Delphi/Object Pascal are you using and with what compiler flags/directives?

Why not just use a [I]free[/I] tool someone already wrote that does exactly what you want, like [URL="

You want to do something non-trivial.

Why not just use [URL="

[quote=montjoile][quote]>>Don't #include C header files in your header files[/quote]
Oohh I didn't know it's wrong to do that.[/quote]
It isn't wrong to do that.

You don't want to #include anything more than you absolutely must, but the whole point of #includes is to make stuff work.

How, for example, would the <sstream> header be able to specify anything useful without #including <string> ? You would have to duplicate information, and that is worse...

I always explain namespaces like having two friends named Jennifer. One is Jennifer Logan and the other is Jennifer Warner. When neither is present, I need to indicate that I am speaking about one or the other by using her full name. When one is present, I just call her "Jennifer", and I refer to the other by her full name. If both are present, I must again specify exactly who I mean.

Hope this helps.

commented: Awesome analog for namespaces. +6

[quote]Why I can't compile without the using namespace std line?[/quote]
You can, but you have to qualify things.

Things like [b]cout[/b] and [b]string[/b] and [b]transform[/b]() are all defined in the [b]std[/b] namespace. If you don't [b]using namespace std[/b] (to tell the compiler that all the stuff in [b]std[/b] is also in the current namespace) then you must explicitly tell the compiler where to find it.
[code=C++]

include <iostream>

void uses_everything()
{
using namespace std; // import everything from 'std' into current
cout << "everything in std is used here.\n";
}

void uses_cout()
{
using std::cout; // import only 'cout' from 'std' into current
cout << "Only 'cout' was used here.\n";
}

void uses_nothing()
{
std::cout << "Nothing was used.\n";
}

int main()
{
uses_everything();
uses_cout();
uses_nothing();
return 0;
}
[/code]
There is a second issue here. Make sure that you [i]never[/i] [b]using[/b] anything in header files.

The file extension on header files has nothing to do with g++, but everything to do with the library author.

The C++ standard requires that certain headers take the form <iostream> and <algorithm> and <cstdio> and the like.

Some people think that was stupid, and use things like ".hpp", as in <boost/any.hpp> and the like.

Some librarys were written in C, or they follow the C convention, and have the ".h" extension, as in "regex.h" and the like.

Just about anything is possible, but most compilers do require you to stick to one of the mentioned conventions.

Hope this helps.

If I'm using a Mac, how am I supposed to put a line in the file that contains a '\r' (without it being treated as an EOL)?

Microsoft function names are not very creative (which is a good thing).

[URL="

Use a [b]std[/b]::[b]stringstream[/b]:
[code=C++]
void Set_Actors(ifstream &fin){
string s;
getline(fin, s);
istringstream ss(s);
for (unsigned n=0; getline(ss, Actors[n], ','); n++){
ss >> ws;
}
}
[/code]
Notice how I use [inlinecode]>> ws[/inlinecode] instead of [inlinecode]ignore(...)[/inlinecode]... it is more robust that way.

Hope this helps.

I don't like the current direction, though. I think embarcadero screwed up on a few things... Alas.

Fix your indentation and you'll see what is going wrong.
Good luck!

Make your [b]menuFuntion[/b]() return whether or not the user elects to continue. So main would look something like:
[code=C++]
bool menuFunction();

int main()
{
while (menuFunction())
;
cout << "Goodbye.\n";
return 0;
}
[/code]
Your [b]exit[/b]() function is a dangerous name conflict, especially just to write something before quitting. Hence, you can get rid of it as I have above. (Or just rename it to something consistent, like [b]exitFunction[/b]() or [b]goodbyeFunction[/b]().)

You might also want to check whether the user entered '9' before asking for the numerator and denominator. "I want to quit." --> "Great! What numerator would you like to use?" Not exactly friendly.

Hope this helps.

On POSIX systems, use [URL="

commented: thanks for the great info +1

What you want to do is an OS-specific function. What Operating System are you using?

Your professor is a jerk. (Anyone who would instruct his students to do something before doing it himself [i]the same way students would[/i] is a jerk.) Using [inlinecode]system( "color 1B" );[/inlinecode] [i]doesn't work[/i] -- that modifies the color of the [i]entire console window[/i].

Since you are on Windows, there are two (good) options to you. The first is to use the Win32 [URL="

It has to do with what type of character input the [I]compiler[/I] expects and what kind of character data your [I]program[/I] expects. Surprisingly, the two may be different.

Unfortunately, anything outside the ASCII range (0..127) is not safe to put in a string/character literal.

Alas.

Hmm, just a good habit I've gotten into. (You just never know when a copy of your object will be used when a reference would have done.)

Stay away from always/never rules. The "Rule of Three" isn't [i]always[/i] the right thing to do. In any case, I meant to keep the examples as simple as possible.

You need to specify the standard you are compiling against. The GCC defaults to using its own extensions.

[inlinecode]g++ -Wall -ansi -pedantic ...[/inlinecode]

Hope this helps.

Sigh. Why is it that [I][B]C++[/B][/I] questions always degenerate into [I][B]C[/B][/I] questions?

@[b]firstPerson[/b]
Your code does not satisfy the OP's requirements. If the OP searches for the word "Hello" in the string "Hello, world!", your code cannot find it because it only delimits on whitespace (which would get the string "Hello," from the file, [i]not[/i] "Hello").

You can recover somewhat from this by "trimming" the unwanted characters from the ends of every [b]word[/b] you find, but it will not help when you read "one,two,three,four" from the file and wish to find "four".

@[b]FatimaRizwan[/b]
If that is not a concern, then [b]firstPerson[/b]'s solution, plus the "trim" function, ought to be enough to get you going.

If it [i]is[/i] a problem, keep reading.

But first, if you want to use C++, please get rid of the C stuff. It will only hurt you later when you fail to learn to do things the right way now.

Granted, this is probably a silly homework assignment, and what follows may be fully ignored. Well, at least I gave it something.

[b]Tokenizing[/b]
Even though this is a fairly old concept it is still very much needed and used.

The way that [b]strtok[/b]() does it is, shall we say, [i]simplistic[/i]. However, we will continue with that model in mind. (Also, I will keep things simple by sticking with the [b]std[/b]::[b]string[/b] and [b]std[/b]::[b]istream[/b] data types.)

First, in order to get substrings from a string, you must know where to break it. Hence my admonition to use [b]find_first_of[/b]() ...

commented: Very helpful code !! +3
commented: Above and beyond! +1

[i]Don't[/i] use [b]strtok[/b](). It is for handling C-strings (not [b]std[/b]::[b]string[/b]s), and it modifies the string.

Use the [b]find_first_of[/b]() and [b]substr[/b]() string member functions instead.

Hope this helps.

He has [inlinecode]#include <windows.h>[/inlinecode], so I believe we can safely assume some things about his operating environment.

On Windows, to wait for an event with a timer, use [URL="

To delete files in other directories, you must provide path information.

An [b]absolute[/b] path doesn't care where your executable is:
[quote]C:\WINDOWS\Media\chimes.wav
/usr/bin/env[/quote](Don't delete either of those, btw.)

A [B]relative[/B] path is relative to the current working directory (which may or may not be where your executable is -- it is wherever the user started your program from).
[quote]images\snoopy.png
../objs/myprog.o[/quote]If you started in (Windows) "D:\MyStuff" then the absolute path would be "D:\MyStuff\images\snoopy.png" or (Unix) "~/myprog/bin" then the path would be "~/myprog/objs/myprog.o".

To delay, use the [URL="

A [b]std[/b]::[b]vector[/b] is guaranteed to maintan contiguous data space -- meaning it cannot handle [i]really large[/i] data.

Use a [b]std[/b]::[b]deque[/b] instead. I looks much the same, but the data need not be stored contiguously -- meaning it can handle a great deal larger amount of data (because it can work with the OS/compiler's memory management more flexibly).

BTW, you shouldn't be using [b]atoi[/b](). Use a [b]stringstream[/b] instead...
[code=C++]

include <sstream>

include <stdexcept>

include <string>

int myatoi( const std::string& s )
{
int result;
std::istringstream ss( s );
ss >> result;
if (!ss.eof()) throw std::runtime_error( "not an integer" );
return result;
}
[/code]
Untested!

Hope this helps.

Sorry I was so grouchy.

commented: get some R and R baby. +22