Quote:
my code is compiling but showing segmentation fault error why?
Compiling just mean that the code respect language syntax, but ut doesn't mean it is worth a Pulitzer.
Use the debugger, it will help you to find where is the crash and probably the reason.
When you don't understand what your code is doing or why it does what it does, the answer is
debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute, it is an incredible learning tool.
Debugger - Wikipedia, the free encyclopedia[
^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[
^]
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
Proper indentation helps reading your code:
#include<stdio.h>
int main()
{
int num[5],i,s,no;
for(i=0;i<5;i++)
{
scanf("%d",&num[i]);
}
printf("enter a number\n");
scanf("%d",&no);
s=search(no,&num[0]);
printf("%d\n",s);
search1(no,num);
}
int i=0;
int search(int no,int *num[i])
{
int x,i;
for(i=0;i<5;i++)
{
if(no==*num[i])
return 1;
}
return 0;
}
int search1(int no,int *num)
{
int i,x,k;
printf("your number %d is present in the list",no);
printf("number\tfrequency");
for(i=0;i<5;i++)
{
for(x=0;x<i+1;x++)
{
k=0;
if(num[i]==num[x] &&i!=x)
{
k=0;
break;
}
else
{
k=1;
continue;
}
}
if(k==1)
printf("%d",num[i]);
}
}