Sunday 11 December 2011

Write a program to find out the character is positive or negetive in c

#include
#include
#include
main()
{
char string[20];
char *ptr,c;
clrscr();
printf("Enter A string:");
gets(string);
printf("Enter a character which u wish to check:");
scanf("%c",&c);
ptr=strchr(string,c);
if(ptr)
printf("The character %c is at position:%d\n",c,ptr-string+1);
else
printf("The character was not found\n");
getch();
}

OUTPUT
Enter A string: MAHESH
Enter a character which u wish to check : A
The character h is at position 7

No comments:

Post a Comment