Topic: | I/O parsing and manipulation |
---|---|
Author: | Peter Bui <pbui@cse.nd.edu> |
Date: | August 28, 2009 |
No need to open physical files
Problem 001:
1 13 4 8 0 1000
I/O tends to be line-oriented plain text
char c;
int i;
float f;
double d;
char s[BUFFER_SIZE];
scanf("%c %d %f %lf %s", &c, &i, &f, &d, &s);
char s[BUFFER_SIZE];
int i;
if (fgets(s, BUFFER_SIZE, stdin) != NULL) {
sscanf(s, "%d", &i);
}
Problem 001:
int start, end;
while (scanf("%d %d", &start, &end) == 2) {
// generate range and check if palindrome
}
printf("%c %d %f %lf %s\n", c, i, f, d, s);
snprintf(s, BUFFER_SIZE, "%d", i); // itoa
printf("%0.2lf\n", d);
using namespace std;
int start, end;
cin >> start >> end;
stringstream ss;
ss << i << ' ' << s << endl;
string s;
while (!getline(cin, s).eof()) {
// process line
}
Problem 001:
int start, end;
while (true) {
cin >> start >> end;
if (cin.eof()) break;
}
cout << str << ' ' << i << endl;
cout.width(8)
cout << right << fixed << d << endl;