Reads a series of chars from the standard input and presents them as a string.
#include <stdio.h>
#define MaxLine 80
#define TRUE 1
int getString(char str[]){ // Reads a series of chars from the
int len; // standard input and presents them as a string
printf("Please enter a new string\n");
for (len=1; (str[len] = getchar()) != '\n'; len++);
str[len] = '\0';
return (--len);
}
int strCmp(char str1[], char str2[], int len1, int len2){
int i, identical = len1==len2;
for (i= 0; identical && str1[i]; identical = str1[i] == str2[i++]);
return (str1[i-1] - str2[i-1] );
}
void main (){
char str1[MaxLine], str2[MaxLine];
int i;
int len1 = getString(str1);
int len2 = getString(str2);
switch (i = strCmp(str1, str2, len1, len2)) {
case 0 : printf("The strings are identical \n");
break;
default : printf("The strings are not identical \n");
break;
}
} //Of main()