EmbLogic's Blog

program not comparing with null…

#include<stdio.h>

int main()
{
char a[]=”hello hellothethe hello the hello the hello”;

char b[]=”the”;
int c=0,i,j=0;
for(j=0;a[j]!=”;j++)
{
/* if(a[j]==’\t’||a[j]==’\n’||a[j]==’ ‘)
{
printf(“space\n”);
continue;
}
// else
*/ // {
i=0;
while(b[i]!=”)
{
if(b[i]!=a[j])
break;
i++;j++;

}
if(b[i]==”)
{
c++;
printf(“%d”,c);
}
else
{
while(a[j]!=”&& a[j]!=’ ‘)             //it is working fine but there are double comparisons than in the next loop…

// while(a[j]!=’ ‘|| a[j]!=”)              //why it not check the null condition…???  //  while doing this case there is showing Garbage value at the end. because it is fail to check the character at the end of the string (which it should)… but there is half comparisons… so less execution time and complexity…
{
printf(“%c “,a[j]);
j++;
}
printf(“\n”);

}
// }
}
printf(“matched %d times\n”,c);
return 0;
}

One Response to program not comparing with null…

  1. sheetal sharma says:

    null compair error is due to wrong compairing if you want to compare you have to mention something.
    in above program you making a[j]!=” which is incorrect
    a[j]!=’ ‘; that correct comparison of a[j] with a space.

Leave a Reply to sheetal sharma Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>