Hello all. Could anyone please give me a little assistance? I have finally gotten my code to compile but it gives me wierd output. I am included sample output of what the output should be. I get the first character to go into the array but it stops there for some reason... any help would be grateful.....
Code:
#include <stdio.h>
#define LIMIT 20
void add_char(char*, char, int*);
int main() {
int z, count=0;
char ch, A[21];
printf("Enter up to 20 unique characters; quit with two control-Ds: ");
scanf(" %c", &ch);
add_char(A,ch, &count);
for (z=0; z<LIMIT; z++)
printf("%c",A[z]);
printf("\n");
}
void add_char(char A[], char ch, int *count) {
int z,p=0;
for(*count=0; *count<LIMIT; (*count)++) {
for(z=0; z<LIMIT; z++) {
if (ch==A[z])
p=-10;
}
if (p!=-10) {
A[*count]=ch;
p=0;
}
else
p=0;
}
}
SAMPLE OUTPUT:
Enter up to 20 unique characters; quit with two control-Ds:
The author are Jeri Hanly and Elliot D. Koffman.
TheautorsJiHnlydED.K
Thanks.