Find occurence of a character in a sting.

Answer Posted / anil kumar nahak

void main()
{
char *st,ch;
int i=0,c=0;
printf("\n Enter The String: ");
gets(st);
printf("\n Enter A character For finding occurance: ");
scanf("%c",&ch);

while(st[i]!='\0')
{
if(st[i]==ch)
c++;
i++;
}
printf("\n %c Present In The String %d Times",ch,c);

}

Is This Answer Correct ?    4 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Want to know how to write a C program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL.

1509


please explain every phase in the "SDLC" in the dotnet.

2165


which of the following shows the correct hierarchy of arithmetic operations in C a) (), **, * or/,+ or - b) (),**,*,/,+,- c) (),**,/,*,+,- d) (),/ or *,- or +

1162


Define recursion in c.

689


What is a example of a variable?

537






What is the size of structure pointer in c?

603


What does node * mean?

694


Explain two-dimensional array.

611


What are formal parameters?

644


When should volatile modifier be used?

536


a way in which a pointer stores the address of a pointer which stores the value of the target value a) reference b) allocation c) multiple indirection d) none

620


Write a function that will take in a phone number and output all possible alphabetical combinations

587


Explain how can a program be made to print the name of a source file where an error occurs?

665


I need testPalindrome and removeSpace #include #define SIZE 256 /* function prototype */ /* test if the chars in the range of [left, right] of array is a palindrome */ int testPalindrome( char array[], int left, int right ); /* remove the space in the src array and copy it over to the "copy" array */ /* set the number of chars in the "copy" array to the location that cnt points t */ void removeSpace(char src[], char copy[], int *cnt); int main( void ) { char c; /* temporarily holds keyboard input */ char string[ SIZE ]; /* original string */ char copy[ SIZE ]; /* copy of string without spaces */ int count = 0; /* length of string */ int copyCount; /* length of copy */ printf( "Enter a sentence:\n" ); /* get sentence to test from user */ while ( ( c = getchar() ) != '\n' && count < SIZE ) { string[ count++ ] = c; } /* end while */ string[ count ] = '\0'; /* terminate string */ /* make a copy of string without spaces */ removeSpace(string, copy, ©Count); /* print whether or not the sentence is a palindrome */ if ( testPalindrome( copy, 0, copyCount - 1 ) ) { printf( "\"%s\" is a palindrome\n", string ); } /* end if */ else { printf( "\"%s\" is not a palindrome\n", string ); } /* end else */ return 0; /* indicate successful termination */ } /* end main */ void removeSpace(char src[], char copy[], int *cnt) { } int testPalindrome( char array[], int left, int right ) { }

2196


Explain what is the most efficient way to store flag values?

684