Look and Say Sequence Program in C

#include 
#include 

char buffer[100]="1";
char old_data[100];
void getNextNumber(void)
{
 int i=0; 
 char count = 49; //'1'
 int index = i;
 int buffer_index = 0;
 memcpy(old_data, buffer, sizeof(old_data));
 memset(buffer,0,sizeof(buffer));
 while(old_data[i] != '\0')
 {
  if (strlen(old_data) == 1)
  {
   buffer[buffer_index++] = old_data[0];
   buffer[buffer_index++] = old_data[0];
   i = 1;
  }else {
   if(old_data[index] == old_data[i+1])
    count++;
   else {
    buffer[buffer_index++] = count;
    buffer[buffer_index++] = old_data[index];
    index=i+1;
    count = 49;    
   }
 
  }
  i++;
 }
 buffer[buffer_index] = '\0';
}

int main(int argc, char *argv[])
{

 int count, i;
 printf("Enter the count\n");
 scanf("%d",&count);

 printf("%s\n", buffer);
 
 for (i = 0;i < count - 1;i++)
 {
  getNextNumber();
  printf("%s\n",buffer);
 }
 return 0;
}

Comments

Popular posts from this blog

bb.utils.contains yocto

Difference between RDEPENDS and DEPENDS in Yocto

make config vs oldconfig vs defconfig vs menuconfig vs savedefconfig