Quantcast
Channel: NULL confusion in C - Stack Overflow
Viewing all articles
Browse latest Browse all 3

NULL confusion in C

$
0
0

I am creating a simple "ascending" program. When I find smallest int in array of int I want to replace it with some other value so it won't come as smallest number again in the array. For that, I assigned that intNULL. But now the results are not as expected.

Please tell me if I am doing anything wrong. If so then what I should replace with the value of that int ?

#include<stdio.h>#include<conio.h>void main(){   clrscr();   int a[10],b,c=0,d=0;   printf("Enter number of values you want to enter \n");   scanf("%d",&b);   printf("Enter values \n");   for(int i=0;i<b;i++)      scanf("%d",&a[i]);   while(c<b)   {       for(int k=0;k<b;k++)      {         for(int j=0;j<b;j++)         {            if(a[k] > a[j])            {                d=1;                }         }         if(d!=1 && a[k]!=NULL)          {            c++;            printf("%d ",a[k]);            a[k]='\0' ; //assigning it as NULL         }         if(c >= b)            break;          d=0;      }   }   getch();}

Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images