Ternary Operator | C++ Tutorial

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

Sir pls let me know why this program is not working

abhinavpeddapalli
Автор

Is that the only ternary operator in c++??

MeIsUser
Автор

/*binary search program using dynamic allocation of strings */


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void main()
{
int i, mid, low, high, n, s;
char **a, **key;

printf("enter the number of strings of n\n");
scanf("%d", &n);

a=(char **)malloc(n*sizeof(char *));
key=(char **)malloc(1*sizeof(char *));
for(i=0;i<n;i++){
a[i]=(char *)malloc(9*sizeof(char ));
}
key=(char *)malloc(9*sizeof(char ));
printf("enter the strings\n");
for(i=0;i<n;i++)
scanf("%s", a[i]);
printf("entered strings are");
for(i=0;i<n;i++)
printf("%s\n", a[i]);

printf("enter the key\n");
scanf("%s", &key[0]);
low=0;
high=(n-1);
for(i=0;low<=high;i++){
mid=(low+high)/2;
s=strcmp(key[0], a[1]);
if(s==0){
printf("found");
exit(0);
}
else if(s<0){
low=mid+1;
}
else if(s>0){
high=mid-1;
}
}
printf("not found");
free(a);
free(key);
}

abhinavpeddapalli