C Program For String Compression

 C Program For String Compression

#include <stdio.h>

#include <string.h>

int main()

{

    char ch[1000];

    printf("Enter the string:\n");

    scanf("%s",ch);

    int length=strlen(ch);

    printf("The length of a string is %d\n",length);

    int count=1;

    for(int i=0;i<length;i++)

    {

        if(ch[i]==ch[i+1])

        {

            count++;

        }

        else

        {

            printf("%c%d",ch[i],count);

            count=1;

        }

    }

    return 0;

}


OUTPUT:


/tmp/9SZwGTxrSM.o

Enter the string:

sanjeevadharsh

The length of a string is 14

s1a1n1j1e2v1a1d1h1a1r1s1h1


=== Code Execution Successful ===

Comments

Popular posts from this blog

C PROGRAMMING BASICS

3.1.24 Test link