| File | Count | Avg Lines | Avg Semicolons |
|---|---|---|---|
| Counts | per File | per File | |
| 1 | 15 | 141 | 104 |
| 2 | 4 | 95 | 70 |
| 3 | 1 | 93 | 48 |
| 4 | 1 | 69 | 39 |
| 5 | 1 | 60 | 26 |
| 000 | 100 | 200 | 300 | |
|---|---|---|---|---|
| 0 | 3 | 1 | ||
| 10 | 3 | |||
| 20 | 3 | |||
| 30 | 3 | 1 | ||
| 40 | ||||
| 50 | 2 | |||
| 60 | 2 | |||
| 70 | 1 | 2 | ||
| 80 | ||||
| 90 | 1 | |||
| Totals | 1 | 14 | 6 | 1 |
| 000 | 100 | 200 | |
|---|---|---|---|
| 0 | 3 | ||
| 10 | 3 | ||
| 20 | 1 | 1 | |
| 30 | 1 | ||
| 40 | 1 | ||
| 50 | 1 | 2 | |
| 60 | 2 | 2 | |
| 70 | |||
| 80 | 2 | ||
| 90 | 3 | ||
| Totals | 8 | 13 | 1 |
| total | pages per procedure | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| procs | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 1 | 1 | |||||||||
| 1 | 1 | |||||||||
| 1*4 | 1 | |||||||||
| 2 | 1 | 1 | ||||||||
| 2*2 | 1 | 1 | ||||||||
| 2 | 1 | 1 | ||||||||
| 2 | 1 | 1 | ||||||||
| 3 | 1 | 1 | 1 | |||||||
| 3 | 1 | 1 | 1 | |||||||
| 3 | 1 | 2 | ||||||||
| 3 | 2 | 1 | ||||||||
| 7 | 6 | 1 | ||||||||
| 7 | 7 | |||||||||
| 11 | 10 | 1 | ||||||||
| 12 | 11 | 1 | ||||||||
| 12 | 11 | 1 | ||||||||
| 14 | 13 | 1 | ||||||||
How People Lost Points
Not handling null input - 2
Not handling the empty prefix - 5
Not handling big commands - 4
Not handling many commands - 2
Not handling duplicates - 2
Not doing prefix matching - 3
Not doing storage management - 10
while( (input=getchar()) != EOF )
switch (input) {
case SPACE:
if (last_digit == COMMAND) {
command_list = realloc(command_list, strlen(command_list) + 2);
if (command_list == 0) {
cout << "Error: Not enough memory." << endl;
exit(-1);
}
strcat (command_list, " ");
}
last_digit = EMPTY;
break;
case ENTER:
break;
default:
command_list = realloc(command_list, strlen(command_list) + 2);
if (command_list == 0) {
cout << "Error: Not enough memory." << endl;
exit(-1);
}
if (input>='A' && input <= 'Z')
input = input+'a'-'A';
token[0] = input;
strcat (command_list, token);
if (last_digit==EMPTY) cmd_number ++;
last_digit = COMMAND;
break;
}
char * Strings
int MAX_LEN_OF_CMD = 300;
char inputCmd[MAX_LEN_OF_CMD];
cin >> inputCmd;
while (!cin.eof()) {
if (noOfCmd > 0)
cout << "," << endl;
cout << " \"" << inputCmd << "\"";
noOfCmd++;
cin >> inputCmd;
}
char * are unsafe and inconvenient - don't use them.
cin.getline(inputCmd, MAX_LEN_OF_CMD)
Always Know Where Array Writes Go
string words[4000];
int counter = 0;
int l;
cin >> words[counter];
while(!cin.eof()) {
l = words[counter].length();
for(int m = 0; m < l; m++) {
if (isupper(words[counter][m]))
words[counter][m] = static_cast(tolower(words[counter][m]));
}
counter++;
cin >> words[counter];
}
string convert_to_uppercase_and_quotes(string input_command) {
// converts string from lower to upper case
// adds \ for quotes
int size = input_command.length();
static string output_command;
for(int x=0; x<=size; x++)
if(input_command[x] >= 'a' && input_command[x] <= 'z')
output_command += (input_command[x]-TO_UPPER);
else {
if (input_command[x] == '\"')
output_command += '\\';
output_command +=input_command[x];
}
return output_command;
}
if (islower(input_command[x])) output_command += toupper(input_command[x])
static necessary?
string s;
while(cin && (cin.peek()!=EOF)) {
void eat_white();
cin >> s;
eat_white();
// and so on.
}
while (cin >> s) {
int size = cmd_in.length();
static string cmd_out;
for (int x = 0; x <= size; x++) {
if (cmd_in[x] >= 'a' && cmd_in[x] <= 'z')
cmd_out += (cmd_in[x] - TO_UPPER);
else{
if (cmd_in[x] == '\"')
cmd_out += '\\';
cmd_out += cmd_in[x];
}
cout << "for (unsigned x = 0; x <= cmd.length(); x++) {\n";
--- Freshmeat, 18 April 2001.
orcmd[0] = ""; cmd[0] += "r"; cmd[0] += "e"; cmd[0] += "d"; cmd[1] = "";
string strarray[] = { "red", . . . };
Hint: The first approach generated a 6 meg file.
const string * command(const string & prefix) {
string comm[] = { "red", . . . };
// and so on
}
or
static const unsigned numwords = 2;
static const string words[numwords+1] = { "red", . . . };
static string matches[numwords+1];
const string *command(const string& s) {
// and so on.
}
Hint: Don't do more work than you have to.
This page last modified on 27 February 2001.