Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Disclosure: My content contains affiliate links.

43,693 questions

57,001 answers

573 users

How to create an ASCII frequency table from a string in C

1 Answer

0 votes
#include <stdio.h>
#include <string.h>

#define SIZE 128

void getASCIIFrequency(const char *str, int frequencyTable[]) {
    int len = strlen(str);

    for (int i = 0; i < len; i++) {
        frequencyTable[(unsigned char)str[i]]++;
    }
}

int main() {
    const char *str = "c c++ c# java python php";
    int frequencyTable[SIZE] = {0};

    getASCIIFrequency(str, frequencyTable);

    for (int i = 0; i < SIZE; i++) {
        if (frequencyTable[i] > 0) {
            printf("%c: %d\n", i, frequencyTable[i]);
        }
    }

    return 0;
}



/*
run:

 : 5
#: 1
+: 2
a: 2
c: 3
h: 2
j: 1
n: 1
o: 1
p: 3
t: 1
v: 1
y: 1

*/

 



answered Oct 17, 2024 by avibootz

Related questions

1 answer 213 views
1 answer 213 views
1 answer 210 views
1 answer 227 views
1 answer 214 views
1 answer 190 views
...