What's new

C & C++ Pa help naman po C programming

Pa help naman po sa function, ano po dapat palitan sa source code ko. Hindi po nag a-output yung frequency ng alphabet letters sa string, yung nag a output tuloy eh yung sa ASCII value ng letters.
C:
#include<stdio.h>
#include<string.h>


int frequencyUC( int count[][27],char *string );


int main(){
    
    
    int count[2][27]=
    {
    {65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90},
    {97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122},
    };
    
    int i, j,s,c, freq, length=0;
    char string[200];
    FILE *ifp;
    int ans;
    
    ifp=fopen("input.txt","rt");
    
    printf("The string read from the file is:\n");
    fscanf(ifp,"%s\n",string);
    printf("\t%s\n",string);
    
    
    while(1)
    {
        if(string[i]=='\0'){
            break;
        }
        else{
            i++;
            length++;
        }
    }
    
    printf("\nString length:%d\n", length);
    
    frequencyUC(count,string);
    
    printf("\nFrequency of the letters in the string:\n");
    
    
    for (i=0;i<26;i++){
        
            printf("\t%c / %c \t %d \n",i+'a', i+'A',count[0][c+i]);
        
    
}
return 0;   
}

int frequencyUC ( int count[][27],char *string ){
    int i=0;
    
for (i=0;string[i]!='\0';i++)
{
    if(string[i]>='a'&& string[i]<='z')
    {
        count[string[i]-'a']+1;
    }
 else if(string[i]>='A'&& string[i]<='Z'){
    count[string[i]-'A']+1;
    }
}


}
 
Last edited:
ts palagay sa code container para po madaling mabasa.
1660273706282.png
 

Attachments

C:
#include <stdio.h>
#include <string.h>

// Main Function
int main()
{
    char S[200];
    
    int i,length;
    FILE *ifp;
    ifp=fopen("input.txt","rt");
    
    printf("The string read from the file is:\n");
    fscanf(ifp,"%s\n",S);
    printf("\t%s\n",S);
    
    
    for (i = 0; S[i] != '\0'; ++i);
    
    printf("\nString length: %d\n", i);
    printf("\nFrequency of the letters in the string:\n");
    
    
    findFrequncy(S);
    return 0;
}

 
// Function to print the frequencies
// of each character of the string
void printFrequency(int freq[],char S[])
{
    int i=0;
    for (i = 0; i < 26; i++) {
 
        // If frequency of the
        // alphabet is non-zero
        if (freq[i] != 0) {
 
            // Print the character and
            // its respective frequency
            printf("%c / %c \t%d\n",
                   i + 'A', i + 'a',freq[i]);
        }
    }
}
 
// Function to calculate the frequencies
// of each character of the string
void findFrequncy(char S[])
{
    int i = 0;
 
    // Stores the frequencies
    // of each character
    int freq[26]={0};
 
    // Traverse over the string
    while (S[i] != '\0') {
 
        // Increment the count of
        // each character by 1
        freq[S[i] - 'A']++;
        freq[S[i] - 'a']++;
 
        // Increment the index
        i++;
    }
 
    // Function call to print
    // the frequencies
    printFrequency(freq, S);
}

hello2.jpeg

Ganon po sana sa another comment ko, na run ko na po kaso parang hindi na satisfy yung sa problem. Pwede po pacheck kung ano po ang dapat palitan?
 

Attachments

C:
#include <stdio.h>
#include <string.h>

// Main Function
int main()
{
    char S[200];
 
    int i,length;
    FILE *ifp;
    ifp=fopen("input.txt","rt");
 
    printf("The string read from the file is:\n");
    fscanf(ifp,"%s\n",S);
    printf("\t%s\n",S);
 
 
    for (i = 0; S[i] != '\0'; ++i);
 
    printf("\nString length: %d\n", i);
    printf("\nFrequency of the letters in the string:\n");
 
 
    findFrequncy(S);
    return 0;
}

 
// Function to print the frequencies
// of each character of the string
void printFrequency(int freq[],char S[])
{
    int i=0;
    for (i = 0; i < 26; i++) {
 
        // If frequency of the
        // alphabet is non-zero
        if (freq[i] != 0) {
 
            // Print the character and
            // its respective frequency
            printf("%c / %c \t%d\n",
                   i + 'A', i + 'a',freq[i]);
        }
    }
}
 
// Function to calculate the frequencies
// of each character of the string
void findFrequncy(char S[])
{
    int i = 0;
 
    // Stores the frequencies
    // of each character
    int freq[26]={0};
 
    // Traverse over the string
    while (S[i] != '\0') {
 
        // Increment the count of
        // each character by 1
        freq[S[i] - 'A']++;
        freq[S[i] - 'a']++;
 
        // Increment the index
        i++;
    }
 
    // Function call to print
    // the frequencies
    printFrequency(freq, S);
}

View attachment 2082111


Ganon po sana sa another comment ko, na run ko na po kaso parang hindi na satisfy yung sa problem. Pwede po pacheck kung ano po ang dapat palitan?
kailangan mo pong iconvert muna letter sa string to ascii(A=65) per iteration then check mo po kung equal yung 65 sa 2d array mo.
 
Just expand this solution and fulfill the other requirements.
Note: You need to expand your learning by studying my sample solution. Don't just copy and paste. Learn the logic and concepts applied. Make some necessary research. Good luck

1660320121015.png


OUTPUT:
Note: di ko na na-edit yung caption. para sa output.
1660320183528.png
 

Attachments

Just expand this solution and fulfill the other requirements.
Note: You need to expand your learning by studying my sample solution. Don't just copy and paste. Learn the logic and concepts applied. Make some necessary research. Good luck

View attachment 2084267

OUTPUT:
Note: di ko na na-edit yung caption. para sa output.
View attachment 2084270
Thank you po, I already tried na po sa una kong source code pero instead na frequency lumalabas yung ASCII value po lumalabas. Thank you po ulit
 

Similar threads

Back
Top