-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathex32.cpp
More file actions
50 lines (38 loc) · 868 Bytes
/
ex32.cpp
File metadata and controls
50 lines (38 loc) · 868 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
CPSC 121-0X
Paul De Palma
depalma
Example 32
*/
//comparing strings: strcmp
#include <iostream>
#include <cstring>
using namespace std;
void compare(char[],char[]);
const int MAX = 81;
int main()
{
char word1[MAX];
char word2[MAX];
cout << "Enter a word" << endl;
cin.getline(word1,MAX - 1,'\n');
cout << "Enter another word" << endl;
cin.getline(word2,MAX - 1,'\n');
compare(word1,word2);
return 0;
}
/*
Pre: Both parameters are C-Strings
Post: Displays a string that indicates the orthographical ordering of
the two parameters.
*/
void compare(char word1[], char word2[])
{
int comp = strcmp(word1,word2);
if (comp < 0)
cout << word1 << " is less than " << word2 << endl;
if (comp == 0)
cout << word1 << " is the same as " << word2 << endl;
if (comp > 0)
cout << word1 << " is greater than " << word2 << endl;
}