top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Please help me to find out the problem in the following C code?

0 votes
376 views

where is the problem in this code???,,,,,

#include<stdio.h>
#define EOS '\0'
int islet(char c)
{

    if(c>='a'&& c<='c')return(1);
    else
    return(0);
}

int main()
{
    char c,inpstr[]="abbbbccccb";
    int q,i,j;
    int count=0;
    printf("%s",inpstr);
    q=1;
    i=0;

   c=inpstr[i];

    while(c!=EOS)
    {
        if(q==1 && (inpstr[0]=='a')){q=2;}
        else  if(q==2 && (inpstr[i>=1 ||i<=19]=='b')&& islet(c) )
            {q=2;}    
             else if(q==2 &&(inpstr[i]=='c') && islet(c)){
                count++;
                if(count>1){printf("%d",count);}

else
                {q=3;}
             }
            else if(q==3 && (inpstr[0]=='b')){q=4;}
                 else{
                    q=5;
                    break;
                 }
      c=inpstr[i++];
    }

  if(q==5){
    printf("illegal");}
  else{
        printf("legal");
    }

  return(0);
}
posted Sep 29, 2017 by Mimi

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button LinkedIn Share Button
what is expected from the code, it helps in narrowing down the issue

Similar Questions
+2 votes
#include <stdio.h>
#include <stdlib.h>

void makeHeap(int heap[],int,int);
int delete(int heap[]);
int no;

int main()
{
    int heap[10],i,num,temp[10],n;

    printf("Enter the number\n");
    scanf("%d",&no);

    n=no;
    for(i=0;i<no;i++)
    {
        scanf("%d",&num);
        makeHeap(heap,num,i);
    }
    printf("The heap element are\n");

    for(i=0;i<no;i++)
        printf("%d\t",heap[i]);

    for(i=n-1;i>=1;i--)
       temp[i]=delete(heap);

    printf("\nThe sorted elements are\n");

    for(i=0;i<n;i++)
       printf("%d\t\t",temp[i]);

    return 0;
}
void makeHeap(int heap[],int data,int index)
{
    int parent,temp;
    heap[index]=data;
    while(index!=0)
    {
        parent=(index-1)/2;
        if(heap[parent]>heap[index])
        {
            temp=heap[parent];
            heap[parent]=heap[index];
            heap[index]=temp;
        }

        index=parent;

    }

}

int delete(int heap[])
{
    int i,left,min,m,c;
    int temp;
    int value=heap[0];

    heap[0]=heap[no-1];
    no--;
    i=0;

    //Problem is  coming in this while loop please help 
    while(i<no)
    {
        left=2*i+1;

        if(heap[left]<heap[i]&&left<=no)
        {
            min=left;
            temp=heap[left];
            heap[left]=heap[i];
            heap[i]=temp;

        }
        else
           min=i;

        if((heap[left+1]<heap[i])&&((left+1)<=no))
        {
           min=left+1;
            temp=heap[left+1];
            heap[left+1]=heap[i];
            heap[i]=temp;
        }
        i=min;
    }

    return value;
}
+1 vote

Assume 1 as land and 0 as water

Input

11111 
10001 
10001 
11111 

Output: matrix is pool

Input

11111 
11001 
11001 
10111 
11111 

Output: matrix is NOT pool

Input

11111 
11001 
11001 
10001 
11111 

Output: matrix is pool

Input

11111 
11101 
11001 
10001 
11111 

Output: matrix is pool

+3 votes

Please let me know any open source c/c++ static code analysis tool, I need to use that tool for stataic analysis

...