//=========================================
//buck sort 4-7-26 1v
//=========================================
//----------------------------------------
#include <stdio.h>
#include <string.h>
#include <ctype.h>
//----------------------------------------
void labelformat(int j, char result[]){
//labelformat(j, result);
char label[30];
sprintf(label, "~ :%c:", 'A' + j);
strcat(result, label);  
strcat(result, "\n");
}
//----------------------------------------
void bucksort(char str[], char del[], char result[]){
//bucksort(str, del, result);   
    char *token;
    char buck[26][1000]; 
    // Enough space for concatenated 
    // tokens per bucket
    
    // Initialize buckets to empty strings
    for (int i = 0; i < 26; i++)buck[i][0] = '\0';
    // Tokenize input string
    token = strtok(str, del);
    while (token != NULL) {
        // Convert first character 
        // to uppercase for indexing
        char c = toupper(token[0]);
        if (c >= 'A' && c <= 'Z') {
            int index = c - 'A';
            // Concatenate token and a 
            // space to the correct bucket
            strcat(buck[index], token);
            strcat(buck[index], " ");
        }
        token = strtok(NULL, del);
    }
// 2D 'buck' array into a 1D 'result'
result[0] = '\0'; // Ensure result 
                 //is empty initially
for (int j = 0; j < 26; j++) {
    if (strlen(buck[j]) > 0) {
        strcat(result, buck[j]);
        labelformat(j, result);
        }
    }
}
//----------------------------------------
int main() {
    char str[] = " Now is the winter of our discontent Made glorious \n summer by this sun of York; And all the clouds that \n lour'd upon our house";
    char result[1000] = ""; // Ensure sufficient 
                            // space
    char del[10] = "'#; ./'";
    printf("%s\n", str);
    bucksort(str, del, result);
    printf("%s\n", result);
    return 0;
//----------------------------------------
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: