Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Ajax C language-qsort and bsearch function

Have Programming Question? Ask it here!
 
 
 


Victor
C language-qsort and bsearch function
1 Answer(s)      4 years and 9 months ago
Posted in : Ajax



Advertisement
View Answers

December 5, 2009 at 4:10 PM


Hi Friend,

bsearch function()

#include <stdlib.h>
#include <ctype.h>
#include <stdio.h>
#include <conio.h>

char alpha[] = {'a','b','c','d'};
int comp(const void *ch, const void *s);

int main(void) {
char ch;
char *p;

printf("Enter a character: ");
ch = getchar();
ch = tolower(ch);
p = (char *) bsearch(&ch, alpha, 26, 1, comp);
if(p) printf(" %c is in alphabet\n", *p);
else printf("is not in alphabet\n");
getch();
return 0;
}
int comp(const void *ch, const void *s) {
return *(char *)ch - *(char *)s;
}

Thanks


Related Tutorials/Questions & Answers:
C language-qsort and bsearch function - Ajax
C language-qsort and bsearch function  Explain qsort and bsearch function doing examples with character array.please also answer my previous question on main()parameters.thanks.  Hi Friend, bsearch function
bsearch() function in C
bsearch() function in C Programming Language This section demonstrates the use bsearch() function in C. This searches function the given key in the array... the character array. To perform the search, the bsearch() function compares the elements
Advertisements
C/C++/JAVA Question on function
C/C++/JAVA Question on function  "Write a function to find out common... other data type also.â?? Question can be solved in C,C++ or JAVA. (Recommneded - C
example of function overriding in c++
example of function overriding in c++  require an example of function overriding in c
Function pointer in c
Function pointer in c  What is the difference between function call with function pointer and without function pointer(normal function call
function overloading in c
function overloading in c  are int func1(int x, int y) and void func1(int x, int y) overloaded? can the functions with same name same arguments but different return types be overloaded
C file fsetpos() function
C file fsetpos() function This section demonstrates the use of fsetpos() function in C. The function fsetpos() is used to set the position of the stream... from the function fgetpos(). Its syntax is: fsetpos(File *stream,const fpos_t
C file fseek() function
C file fseek() function This section demonstrates the use of fseek() function in C. This function sets the file position indicator for the stream pointed... with an example. In the following code, the function fopen(file, "w"
C Pointer to a function
; function in C. C provides a special feature of  pointer to a function. As you know  that every function defined in C language have a base address... C Pointer to a function   
java equivalent of c function htonl & htons
java equivalent of c function htonl & htons  hi is there any java equivalent for the c function htonl & htons
Main function parameter in C language - Ajax
Main function parameter in C language  Please let me know how...; Hi Friend, int main(int argc, char **argv) The main function serves.... The fgetpos function gets the current value of the stream argument?s file
How ro convert char into string using recursive function in c#??
How ro convert char into string using recursive function in c#??  This coding is for java...but i want this in c# How ro convert char into string using recursive function in c#?? char [] ch={'H','E','L','L','o'}; TO ans
C file fgetpos() function
C file fgetpos() function This section demonstrates you the use of fgetpos() function. This function get the current read/write position of stream and stores...() function to return to the same position. Its syntax is: fgetpos(File *stream
c++
c++  write a prgrm tht accepts 3 integer values,then with a function to swap the values
c++
c++  .write a program that accepts 5 subjects of a student,it should have a function to calculate the average & another function to grade.grade should be as follows-<40=E,40-49=D,50-59=C,60-69=B & >70
c++
c++  .write a prgrm tht accepts 5 subjects of a student,it shld hv a function to calculate the average & another function to grade.grade shld be as follows-<40=E,40-49=D,50-59=C,60-69=B & >70
c++
c++  write a prgrm tht calculates the surface area of a cylinder.the prgrm shld find the circumfrance and have a function that calculates the fadius and another to calculate the surface area
c++
c++  Consider the following function: int funcExercise7(int list[], int size) { int sum = 0; for (int index = 0; index < size; index++) sum = sum + list[index]; return sum
c++
c++  Consider the following declarations: class xClass { public: void... private members does class xClass have? c. How many constructors does class xClass have? d. Write the definition of the member function func so that u is set to 10
c++
c++  Consider the following declarations: class xClass { public: void... private members does class xClass have? c. How many constructors does class xClass have? d. Write the definition of the member function func so that u is set to 10
function
function  difference between function overloading and operator overloading
C++
C++  How can i write this in dev c
C++
C++  How can i write this in dev c
c#
c#  how to find out the size of the BMP image in C
c++
c++  use a prgrm as an example to xplain-: a)class b)object c)message d)cope resolution operator
c++
c++  write a programme that calculates the area and circumference of a rectangle
c#
c#  how to find out the size of the BMP image
c++
c++  i use turbo c++...i want to change the background color...what is the command for it and the header file used
c++
c++  i use turbo c++...i want to change the background color...what is the command for it and the header file used
c++
c++  i use turbo c++...i want to change the background color...what is the command for it and the header file used
C++
C++  dear sir How to create windows form application for login screen using C++? USER Name -TESTADMIN Password -testuser
c++
c++  differenciate btw.-a)local & public variables b)pre-defined & user defined functions c)fnctn prototype,defination & fnctn code.use code examples
c++
c++  differenciate btw.-a)local & public variables b)pre-defined & user defined functions c)fnctn prototype,defination & fnctn code.use code examples
C++
C++  differenciate btw.-a)local & public variables b)pre-defined & user defined functions c)fnctn prototype,defination & fnctn code.use code examples
C++
C++  Describe the principle advantages of deploying a linked list versus a static array when implementing a Queue or a Stack
C++
C++  Trace the bubble sort using the following integers,which represent the elements in an array. 5,7,3,8,6,7,3
C++
C++  I have been asked to write a programme that gets five values,gets the sum,average and product please help me
C#
C#  i need a code that will make program perform the basic operations upon the data Listview save, update and cancel
c++
c++  write a program that gets a key or character from the keyboard and displays it ASII code in decimal, hexadecimal and binary form.It must also give a description of the key pressed
C++
C++  write a prgrm tht gets five values,gets the sum,average &...; #include <conio.h> void main() { clrscr(); int a,b,c,d,e,sum; float average...;>b>>c>>d>>e; sum=a+b+c+d+e; average=sum/5; product=a*b*c*d
C#
C# register form  i want to generate a user id automatically after filling their register form and i want to show their id to their email? please reply me soon
c++
c++  Write a console based C++ program that reads student information from a text file, build an array of objects of type class StudentInfo... name with the minimum GPA 7) Display Student GPAs as Letter Grades (A, B, C, D
c++
c++  Characterize the following algorithm in terms of Big-O notation. Also find the exact number of additions executed by the loop. (Assume that all variables are properly declared.) for (int i = 1; i <= n; i++) sum = sum + i
c++
c++  Characterize the following algorithm in terms of Big-O notation. for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) for (int k = 1; k <= n; k++) cout << i + j + k
C++
C++  . Consider the definition of the following class: class CC { public: CC(); //Line 1 CC(int); //Line 2 CC(int, int); //Line 3 CC(double, int); //Line 4 . . . private: int u; double v
c++
c++  Write the definition of the class dayType that implements the day of the week in a program. The class dayType should store the day... on an object of type dayType: a. Set the day. b. Print the day. c. Return the day
c++
c++   Assume vector "x" of integers with values of 7, 3, 5, 8, 1, 9, 0, 4, 2, 6. Second, assume integer variables "a," "b" and "y" with values of 3, x.size()-5 and 0, respectively. Third, assume a for-loop header which: 3.1
c++
c++  write a programme that calculates the area and circumference of a rectangle   #include<conio.h> #include<iostream.h> class rect { int l,b; int area; int peri; public: void get_rect() { cout<<"\n
C,C++
C,C++  Sir, 100&30 gives output 4 in C++ and 100|30 gives output 116 How & and | gives output 4 and 116
C/C++ QUESTIONS
C/C++ QUESTIONS  ??Write a function for finding out the occurences of repeated word from a sentence. This function would return an array of duplicate words.
Advertisements
 

 

 

DMCA.com