Finding first/last occurrence of a character in a string
without using strchr( ) /strrchr( ) function.
Answers were Sorted based on User's Feedback
Answer / sepideh
#include<iostream>
#include<conio.h>
using namespace std;
int main(){
char m[20];
char x;
gets(m);
x=getch();
for(int i=0;i!=null;i++)
if(m[i]==x){
cout<<i;}
getch();}
| Is This Answer Correct ? | 9 Yes | 0 No |
Answer / daniel
#include <stdio.h>
#include <string.h>
int main()
{
char *string = "This is a simple string";
char x = 's';
int i;
int focc, locc;
for (i=0;i<strlen(string);i++){
if (string[i] == x){
focc = i;
break;
}
}
for (i=0;i<strlen(string);i++){
if (string[i] == x)
locc = i;
}
printf ("First occurrence %d, last occurrence %d\n", focc, locc);
return 0;
}
| Is This Answer Correct ? | 8 Yes | 4 No |
WHAT IS INT?
what does ‘segmentation violation’ mean?
What is the mean of function?
List the difference between a While & Do While loops?
A SIMPLE PROGRAM OF GRAPHICS AND THEIR OUTPUT I WANT SEE WAHAT OUTOUT OF GRAPHICS PROGRAM
Explain can the sizeof operator be used to tell the size of an array passed to a function?
Which programming language is best for getting job 2020?
Explain what is dynamic data structure?
Explain the concept and use of type void.
what is the function of .h in #include<stdio.h> in c ?
23 Answers HCL, IBM, Wipro,
Which of the following operators is incorrect and why? ( >=, <=, <>, ==)
what are bps & baud rates? differentiate these two?