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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
#include <stdio.h>
#include <string.h>
#include <string>
void combineStrings(char *stringOne, char *stringTwo);
void wordComparison(char *wordOne, char *wordTwo);
int main (void)
{
int answer; /*answer for what function*/
char stringOne [40]; /* holds string 1 for word combination */
char stringTwo [40]; /* holds string 2 for word combination */
char wordOne [20]; /* holds word 1 for choice 2 */
char wordTwo [20]; /* holds word 2 for choice 2 */
char sentence [200]; /* holds words for sentence*/
printf( "Choose a function by enterting the corresponding number: \n"
"1) Enter two Strings to be combined\n"
"2) Compare two Strings\n"
"3) Count and Convert a sentence to lowercase letters\n"
"4) Convert and Output Birthdate\n"
"5) Quit program\n" );
scanf( "%d", &answer );
flushall();
while (answer >= 1 && answer < 5) {
if (answer == 1) {/*choice one*/
printf( "\nYou have chosen to enter two strings to be strung together\n"
"Please enter the first string:\t");
gets( stringOne );
printf( "Please enter the second string:\t" );
gets( stringTwo );
combineStrings(&stringOne[40], &stringTwo[40] );
}
/*choice 2*/
if (answer == 2) {
/* gather user input */
printf( "\nYou have chosen to compare two words\n"
"Please enter the first word:\t");
gets( wordOne );
printf( "Please enter second word:\t");
gets( wordTwo );
/* call function to compare entered words */
wordComparison( &wordOne[20], &wordTwo[20] );
} /* end if */
/*choice 3*/
if (answer == 3) {
}
printf( "Choose a function by enterting the corresponding number: \n"
"1) Enter two Strings to be combined\n"
"2) Compare two Strings\n"
"3) Count and Convert a sentence to lowercase letters\n"
"4) Convert and Output Birthdate\n"
"5) Quit program\n" );
scanf( "%d", &answer );
flushall();
}/*end if*/
}/*end main*/
void combineStrings (char *stringOne, char *stringTwo )
{
char stringThree[80];
printf( "\nString one is %s\nString two is %s\n", stringOne, stringTwo );
strcpy(stringThree, stringOne);
strcat(stringThree, "?");
strcat(stringThree, stringTwo);
printf( "\nBoth strings = %s\n\n", stringThree );
}
void wordComparison( char *wordOne, char *wordTwo )
{
/* hold result of string comparison */
int result; /* shows if words are identical or not */
printf( "\nWord one is = %s\n\n", wordOne );
printf( "\nWord two is = %s\n\n", wordTwo );
/* compare the entered words */
result = strcmp ( wordOne, wordTwo );
if (result == 0) { /* strncmp returns 0 if the words are identical */
printf( "\nThe words are identical.\n\n" );
} /* end if */
if (result > 0) { /* strncmp returns 0 if the words are identical */
printf( "\nWord one is greater than word two.\n\n" );
}
if (result < 0) { /* strncmp returns 0 if the words are identical */
printf( "\nWord one is less than word two.\n\n" );
}
} /* end wordComparison */
|