C program to search for a given character in a string, C/C++ Programming

Program is to search for a given character in a string:

Program is to search for a given character in a string and print point of match

char *stsearch(char *string, char search);

void main()

 {

 clrscr();

 char string[20],search,*temp;

 int i=0;

 cout<<" enter a string ";

 gets(string);

 cout<<" enter the letter to be searched in a string ";

 cin>>search;

 

 temp=stsearch(string,search);

 

 cout<<"String after char search : "<

}

 

char *stsearch(char *string, char search)

{

 int i=0;

 while (string[i]!='\0')

   {

     if(search==string[i])

     {

                cout<<" The Character is found : "<<"\n";

                return &string[i];

     }

     i++;

   }

   cout<<" The char is not found ";

   return NULL;

}

 

 

Posted Date: 10/19/2012 5:45:24 AM | Location : United States







Related Discussions:- C program to search for a given character in a string, Assignment Help, Ask Question on C program to search for a given character in a string, Get Answer, Expert's Help, C program to search for a given character in a string Discussions

Write discussion on C program to search for a given character in a string
Your posts are moderated
Related Questions

Design and implement a library system that does the following: ? Takes details of a student/library users: first name, last name, other names, user ID number, and nationality. Th

A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindrome

Write a C++ program according to the following specifications 1. Display a brief description of the program. 2. Ask the user to specify the type of loading (end load, intermediate

Program is to store all ASCII char into a file: void main()     {   ofstream  fout("ascii.txt");   int i,n=256;   for(i=1;i     {     fout     }

Program is to store marks and name, roll no in a file: class stud   {     int rno;     char name[20];     int m1,m2,m3;     public:                 void acce

Write a function to accept a character and display it 40 times.

We can combine more than one variable on the same line i.e.   float number1,number2,number3; etc Sometimes we want to mix the variable types used on the same line, this could

By pressing ‘6’ (i.e. key’6’ one time) on the keypad, the mobile shows ‘m’ on display screen in write text message area .

For Loop with inner loop