This code's working fine just that when i enter the value to be stored in the array for linear search it says " POINTER (2) 0x2487 PROCESSOR FAULT"
Expand|Select|Wrap|Line Numbers
- #include<stdio.h>
- void main()
- {
- int *a, *b, count, i,x,found,val,n;
- char newN,ch;
- b=a;
- printf("Enter the size of array : ");
- scanf("%d", &n);
- count=0;
- while(n!=0)
- { a++;
- count++;
- n--;
- }
- a=b;
- for(i=0;i<count;i++)
- {
- printf("Enter value for %d element ", i);
- scanf("%d", & val);
- a[i]=val; /*Here's the problem lies, i've tried using & and * operators but no help */
- }
- do{
- found=0;
- printf("\nEnter the element to be searched :");
- scanf("%d", &x);
- for(i=0;i<count;i++)
- {
- if(a[i]==x)
- {found=1;
- break;
- }
- }
- if(found==1)
- printf("\nThe element has been found at position %d!",i+1);
- else
- printf("\n %d was not found!",x);
- fflush(stdin);
- printf("\nSearch another element ? (Y/N) : ");
- scanf("%c", &ch);
- found=0;
- }while(ch=='y'||ch=='Y');
- }