I am to get input from the user and remove everything except the capital letters. However I do not want duplicate capital letters. Thus far the only issue I am having is removing the duplicates.
Here is the code to both sort the letters and place only the ones I want into a new array.
placer=0;
for (a = 0 ; a < ( strlen(regular) - 1 ); a++)
{
for (placer = 0 ; placer < strlen(regular) - a - 1; placer++)
{
if (regular[placer] > regular[placer+1])
{
swap = regular[placer];
regular[placer] = regular[placer+1];
regular[placer+1] = swap;
}
}
}
printf("regular: %s\n", regular); // this prints exactly as it is supposed to
placer=0;
for (a=0; a<strlen(regular); a++){
if (regular[a] != regular[a+1]){
alpha[placer] == regular[a];
placer++;
}
}
printf("alpha: %s\n", alpha); // this does not
As it stands the array alpha will for unknown reasons not take any characters whatsoever. Every time I try to print it, it just prints garbage.
And just to clarify:
char regular[81+1]="\0", alpha[26];
That is the declaration of the 2 arrays.
Any help would be appreciated.
You have mistaken "==" for "=" in line alpha[placer] = regular[a];.
So this should be
alpha[placer] = regular[a];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.