aaabb to32 ,aabbb to a2b3 convert in c-asr
/******************************************************************************
Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char s[10],c[10];
int i=1,j,tmp[10];
int p[10];
static int x,num=0;
s[0]='*';
c[0]='*';
tmp[0]=0;
printf("\nEnter a string\n");
while(1){
s[i]=getchar(); //reads single characters until enter pressed
if(s[i]==s[i-1]) //checks the previous character matched or not
{
x++;
tmp[num]=x; //increment x as much as character matches the previous characters insert into tmp
}
else{
x=1;
c[num]=s[i-1];
num++;
tmp[num]=x; //if not matched then x is 1 as above in starting of else block
}
if(s[i]=='\n'){ //press enter to come out of loop
break;
}
i++;
}
for(j=1;j<num;j++){
printf("%d ",tmp[j]); //prints number of counts of same character
}
printf("\n");
for(j=1;j<num;j++){
printf("%c%d",c[j],tmp[j]); //prints number of counts of same character
}
getch();
return 0;
}
Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char s[10],c[10];
int i=1,j,tmp[10];
int p[10];
static int x,num=0;
s[0]='*';
c[0]='*';
tmp[0]=0;
printf("\nEnter a string\n");
while(1){
s[i]=getchar(); //reads single characters until enter pressed
if(s[i]==s[i-1]) //checks the previous character matched or not
{
x++;
tmp[num]=x; //increment x as much as character matches the previous characters insert into tmp
}
else{
x=1;
c[num]=s[i-1];
num++;
tmp[num]=x; //if not matched then x is 1 as above in starting of else block
}
if(s[i]=='\n'){ //press enter to come out of loop
break;
}
i++;
}
for(j=1;j<num;j++){
printf("%d ",tmp[j]); //prints number of counts of same character
}
printf("\n");
for(j=1;j<num;j++){
printf("%c%d",c[j],tmp[j]); //prints number of counts of same character
}
getch();
return 0;
}
Comments
Post a Comment