|
CS256 - Principles of Structured Design
Fall 2021
|
Displaying ./code/sternflCode/cipher1.c
#include<stdio.h>
#include<string.h>
void prtAlpha(char a[]) {
for(int i=0; i<26;i++)
printf("%c", a[i]);
printf("\n");
}
//non zero : true (is a duplicate)
//zero: false (is NOT A dup)
int isDup(int in, int numletters, char noDup[]) {
for(int i=0; i<numletters; i++)
if (in==noDup[i]) return 1;
return 0;
}
int main() {
char clearAlpha[26];
char cipherAlpha[26];
for (int i=0; i<26; i++)
clearAlpha[i] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i];
prtAlpha(clearAlpha);
printf("Please enter your key word >");
char keyWord[26];
scanf("%s", keyWord);
printf("the key word is %s\n", keyWord);
char noDup[26];
int len = strlen(keyWord);
//size of noDup
int sz=0;
for(int i=0; i<len; i++)
if (!isDup(keyWord[i], sz, noDup)) {
noDup[sz] = keyWord[i]; //was an i instead of sz
sz++;
}
for(int i=0; i<sz; i++)
printf("%c", noDup[i]);
printf("\n");
}
|