How to use the ternary operator in C++. Source code: github.com/portfoliocourses/c.... Check out www.portfoliocourses.com to build a portfolio that will impress employers!
/*binary search program using dynamic allocation of strings */ #include #include #include void main() { int i,mid,low,high,n,s; char **a,**key; printf("enter the number of strings of n "); scanf("%d",&n); a=(char **)malloc(n*sizeof(char *)); key=(char **)malloc(1*sizeof(char *)); for(i=0;i
It looks like you want to use key to store a string, but you have declared key as char ** and used malloc twice with it, once as if it is char ** and then as if it is char *. That seems really unusual to me, I think you want key to be a char * so you can dynamically allocate space to store a string to be the key. These videos might help you out and give you ideas to solve the problem you are trying to solve: Binary Search Algorithm: th-cam.com/video/Uuyv88Tn9iU/w-d-xo.html Dynamically Allocate Memory for Array Of Strings: th-cam.com/video/4_2BEgOFd0E/w-d-xo.html Sorting An Array Of Strings: th-cam.com/video/LZNxRSoEG2M/w-d-xo.html
Superb
Than you Abhinav! :-)
my I ask which editor is it?
Sir pls let me know why this program is not working
Is that the only ternary operator in c++??
Yes. :-)
Its urgent
/*binary search program using dynamic allocation of strings */
#include
#include
#include
void main()
{
int i,mid,low,high,n,s;
char **a,**key;
printf("enter the number of strings of n
");
scanf("%d",&n);
a=(char **)malloc(n*sizeof(char *));
key=(char **)malloc(1*sizeof(char *));
for(i=0;i
It looks like you want to use key to store a string, but you have declared key as char ** and used malloc twice with it, once as if it is char ** and then as if it is char *. That seems really unusual to me, I think you want key to be a char * so you can dynamically allocate space to store a string to be the key.
These videos might help you out and give you ideas to solve the problem you are trying to solve:
Binary Search Algorithm: th-cam.com/video/Uuyv88Tn9iU/w-d-xo.html
Dynamically Allocate Memory for Array Of Strings: th-cam.com/video/4_2BEgOFd0E/w-d-xo.html
Sorting An Array Of Strings: th-cam.com/video/LZNxRSoEG2M/w-d-xo.html