Write a program that invokes a function called find() to perform the following tasks:
(a) Recieves a character array and a single character.
(b) Returns 1 if the specified character is found in the array, 0 otherwise.
#include <stdio.h>
#include <string.h>
void find(char str[20],char character);
void main()
{
char str[20],ch;
clrscr();
printf("Enter a String:");
scanf("%s",str);
printf("Enter a character to Search:");
scanf("%s",&ch);
find(str,ch);
getch();
}
void find(char str[20],char character)
{
if(strchr(str,character)!=0)
putchar('1');
else
putchar('0');
}
OUTPUT
Enter a String : PROGRAMMING
Enter a character to Search : M
1
Enter a String : PROGRAMMING
Enter a character to Search : U
0
(a) Recieves a character array and a single character.
(b) Returns 1 if the specified character is found in the array, 0 otherwise.
#include <stdio.h>
#include <string.h>
void find(char str[20],char character);
void main()
{
char str[20],ch;
clrscr();
printf("Enter a String:");
scanf("%s",str);
printf("Enter a character to Search:");
scanf("%s",&ch);
find(str,ch);
getch();
}
void find(char str[20],char character)
{
if(strchr(str,character)!=0)
putchar('1');
else
putchar('0');
}
OUTPUT
Enter a String : PROGRAMMING
Enter a character to Search : M
1
Enter a String : PROGRAMMING
Enter a character to Search : U
0
No comments:
Post a Comment