Code:
/*
Words are from the Roberta Flack version of the song, 1969, from here:
http://www.youtube.com/watch?v=hOFrGbuUqnQ
Great listen! ;)
*/
#include <stdio.h>
#include <string.h>
#include <time.h>
int encrypt (int num);
int main(void) {
char a[]={
"The first time, ever I saw your face.\n"
"I thought the sun, rose in your eyes.\n"
"And the moon and the stars, were the gifts you gave,\n"
"to the dark, and the endless skies, my love.\n"
"To the dark, and the endless skies.\n\n"
"And the first time, ever I kissed your mouth.\n"
"I felt the earth, move in my hand.\n"
"Like the trembling heart, of a captive bird,\n"
"that was there, at my command, my love.\n"
"That was there, at my command, my love.\n\n"
"And the first time, ever I lay with you,\n"
"I felt your heart, so close to mine.\n"
"And I knew our joy, would fill the earth,\n"
"and last, till the end of time, my love.\n"
"And it would last, till the end of time, my love.\n\n"
"The first time, ever I saw, your face.\n"
"Your face. Your face. Your face.\n"
};
char b[]={
"The first time, ever I saw your face.\n"
"I thought the sun, rose in your eyes.\n"
"And the moon and the stars, were the gifts you gave,\n"
"to the dark, and the endless skies, my love.\n"
"To the dark, and the endless skies.\n\n"
"And the first time, ever I kissed your mouth.\n"
"I felt the earth, move in my hand.\n"
"Likes the trembling heart, of a captive bird,\n" //appended an s to Like,
"that was there, at my command, my love.\n"
"That was there, at my command, my love.\n\n"
"And the first time, ever I lay with you,\n"
"I felt your heart, so close to mine.\n"
"And I knew our joy, would fill the earth,\n"
"and last, till the end of time, my love.\n"
"And it would last, till the end of time, my love.\n\n"
"The first time, ever I saw, your face.\n"
"Your face. Your face. Your face.\n"
};
char counta[127], countb[127];
int i, lena, lenb, maxlen, notEqual;
clock_t start,stop;
start=clock();
for(i=0;i<127;i++) {
counta[i]=0;
countb[i]=0;
}
lena=strlen(a); //get their respective lengths
lenb = strlen(b);
if(lena > lenb)
maxlen = lena;
else
maxlen = lenb;
for(i=0;i<=maxlen;i++) { //and catalogue the values
if(i<lena)
counta[a[i]]++;
if(i<lenb)
countb[b[i]]++;
}
for(i='A',notEqual=0;i<='z';i++) { //now compare them
if(counta[i] != countb[i]) {
notEqual = 1;
printf("Not equal: %c counta[i]: %d countb[i]: %d\n",i,counta[i], countb[i]); //getchar();
break;
}
//printf("i: %c Is equal: counta[i]: %d countb[i]: %d\n",i,counta[i], countb[i]); getchar();
}
if(notEqual)
printf("Strings contain different letters\n\n");
else
printf("Strings contain the same letters\n");
stop = clock();
printf("Elapsed time: %f seconds\n",(double)(stop-start)/CLOCKS_PER_SEC);
printf("Display the strings [y/any] ? ");
i=getchar();
if(i=='y')
printf("a:\n%s\n\n b:\n%s\n",a,b);
return 0;
}