Key sequence to generate end-of-file signal?
I've got some ported code that wants me to enter the
end-of-file signal from my keyboard. Couldn't fine the needle
at Apple Developer's haystack.
The documentation even says that this would be control+z on
Microsoft Windows or control+d for Unix of Linux systems.
Alas, no Mac OS X flavor.
Anybody know this? I tried all of Apple's modififiers + d/z.
end-of-file signal from my keyboard. Couldn't fine the needle
at Apple Developer's haystack.
The documentation even says that this would be control+z on
Microsoft Windows or control+d for Unix of Linux systems.
Alas, no Mac OS X flavor.
Anybody know this? I tried all of Apple's modififiers + d/z.
Control-d should do it from the Terminal application.
Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Mac OS X is unix...
I've been doing a Debug->Run Log to run the thing.
I take it that that is not the terminal.
Do I need a certain type of project to get a terminal?
Right now I'm using a Application > Carbon Application
Do I need a Command Line Utility > C++ Tool or something else?
I take it that that is not the terminal.
Do I need a certain type of project to get a terminal?
Right now I'm using a Application > Carbon Application
Do I need a Command Line Utility > C++ Tool or something else?
You can run applications from the Terminal (this refers to Terminal.app, not a certain type of application)
I know you can run C/C++ tools by executing the file, and applications by executing MyApp.app/Contents/MacOS/MyApp, but I don't know about Carbon applications...
I know you can run C/C++ tools by executing the file, and applications by executing MyApp.app/Contents/MacOS/MyApp, but I don't know about Carbon applications...
Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Just stumbled across this:
In the project under Products/MyApps.app/Contents/MacOS/MyApps is a
little dark grey rectangular icon next to it. I was never sure what this is
until now, it's a (very minimized) terminal window icon. Double clicking
opens up the Carbon application in that terminal window.
Control+D works beautiful
Well, I have to do it twice, but that's a minor quible.
Thanks again.
In the project under Products/MyApps.app/Contents/MacOS/MyApps is a
little dark grey rectangular icon next to it. I was never sure what this is
until now, it's a (very minimized) terminal window icon. Double clicking
opens up the Carbon application in that terminal window.
Control+D works beautiful
Well, I have to do it twice, but that's a minor quible.
Thanks again.
control-D should work the first time. Are you sure you're doing control-D without any input on the current line?
Yes, quite sure there is input on the line before ctrl+d.
I take it that I need to hit return key and then ctrl+d (or something to
that effect)
I take it that I need to hit return key and then ctrl+d (or something to
that effect)
Could be a buffering issue...
However, it usually shouldn't hurt to do it twice if that's what works.
However, it usually shouldn't hurt to do it twice if that's what works.
Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
It also might depend on how you get your input. For example, if you use getchar(), it will immediately get EOF at the end of file. If you are using something like while (!feof(file)) or, with an istream is, while (is.good), it will be delayed. Basically, you have to try to get input at the end of file, then it will set the EOF flag. So if you put while (TRUE) or while (true) (depending on if it's C or C++), then grab your input, then check to see if it's EOF and quit if it is, it won't need to be put in twice.
Here's the code verbatim: If there's a tweak to improve it, I'm all ears (uhh make that eyes)
cout << "Enter all your homework grades, "
"followed by end-of-file: ";
// the number and sum of grades read so far
int count = 0;
double sum = 0;
// a variable into which to read
double x;
// invariant:
// we have read `count' grades so far, and
// `sum' is the sum of the first `count' grades
while (cin >> x)
{
++count;
sum += x;
}
cout << "Enter all your homework grades, "
"followed by end-of-file: ";
// the number and sum of grades read so far
int count = 0;
double sum = 0;
// a variable into which to read
double x;
// invariant:
// we have read `count' grades so far, and
// `sum' is the sum of the first `count' grades
while (cin >> x)
{
++count;
sum += x;
}
try doing this for your loop:
Code:
while (true)
{
cin >> x;
if (cin.eof())
break;
++count;
sum += x;
}
Nope. Tried the above and it still needs two control+d. The first time
displays ^D and the second time the program ends. This is not my code
so there is no ego here. If anybody cares here's the code in it's entirety.
The book specifically only mentions Windows and Linux. Could Mac OS X
BSD Unix behave differently? I don't have either a windows or linux machine
handy.
int main()
{
// ask for and read the student's name
cout << "Please enter your first name: ";
string name;
cin >> name;
cout << "Hello, " << name << "!" << endl;
// ask for and read the midterm and final grades
cout << "Please enter your midterm and final exam grades: ";
double midterm, final;
cin >> midterm >> final;
// ask for the homework grades
cout << "Enter all your homework grades, "
"followed by end-of-file: ";
// the number and sum of grades read so far
int count = 0;
double sum = 0;
// a variable into which to read
double x;
// invariant:
// we have read `count' grades so far, and
// `sum' is the sum of the first `count' grades
while (cin >> x)
{
++count;
sum += x;
}
// write the result
streamsize prec = cout.precision();
cout << endl << "Your final grade is " << setprecision(3)
<< 0.2 * midterm + 0.4 * final + 0.4 * sum / count
<< setprecision(prec) << endl;
return 0;
}
displays ^D and the second time the program ends. This is not my code
so there is no ego here. If anybody cares here's the code in it's entirety.
The book specifically only mentions Windows and Linux. Could Mac OS X
BSD Unix behave differently? I don't have either a windows or linux machine
handy.
int main()
{
// ask for and read the student's name
cout << "Please enter your first name: ";
string name;
cin >> name;
cout << "Hello, " << name << "!" << endl;
// ask for and read the midterm and final grades
cout << "Please enter your midterm and final exam grades: ";
double midterm, final;
cin >> midterm >> final;
// ask for the homework grades
cout << "Enter all your homework grades, "
"followed by end-of-file: ";
// the number and sum of grades read so far
int count = 0;
double sum = 0;
// a variable into which to read
double x;
// invariant:
// we have read `count' grades so far, and
// `sum' is the sum of the first `count' grades
while (cin >> x)
{
++count;
sum += x;
}
// write the result
streamsize prec = cout.precision();
cout << endl << "Your final grade is " << setprecision(3)
<< 0.2 * midterm + 0.4 * final + 0.4 * sum / count
<< setprecision(prec) << endl;
return 0;
}
I'd love some follow-up on this question- I've run into the same issue with this example from "Accelerated C++". I'm using XCode 2.4.1.
A reference elsewhere (thanks Hayne), revealed that the key presses
ctrl-d
ctrl-q
return
do the trick. It seems that ctrl-d should work (this is the EOF key combination for UNIX machines, it's ctrl-z for MS Windows machines), but that the run window in Xcode is only simulated, and that the best way to run the program is using the terminal itself. Hayne knew the answer from the Xcode mailing list (see http://www.cocoadev.com).
Robin.
ctrl-d
ctrl-q
return
do the trick. It seems that ctrl-d should work (this is the EOF key combination for UNIX machines, it's ctrl-z for MS Windows machines), but that the run window in Xcode is only simulated, and that the best way to run the program is using the terminal itself. Hayne knew the answer from the Xcode mailing list (see http://www.cocoadev.com).
Robin.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| generate MD5 strings with Objective-C? | fernandovalente | 3 | 3,628 |
Jan 27, 2010 09:29 AM Last Post: Hog |
|
| Using a matrix to generate a new vector position | imikedaman | 6 | 3,735 |
Jul 16, 2006 01:17 PM Last Post: imikedaman |
|

