Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


Finding first/last occurrence of a character in a string
without using strchr( ) /strrchr( ) function.

Answers were Sorted based on User's Feedback



Finding first/last occurrence of a character in a string without using strchr( ) /strrchr( ) functi..

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

Finding first/last occurrence of a character in a string without using strchr( ) /strrchr( ) functi..

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

Post New Answer

More C Interview Questions

WHAT IS INT?

8 Answers   Accenture,


what does ‘segmentation violation’ mean?

1 Answers  


What is the mean of function?

0 Answers  


List the difference between a While & Do While loops?

0 Answers   Accenture,


A SIMPLE PROGRAM OF GRAPHICS AND THEIR OUTPUT I WANT SEE WAHAT OUTOUT OF GRAPHICS PROGRAM

0 Answers   HCL,


Explain can the sizeof operator be used to tell the size of an array passed to a function?

0 Answers  


Which programming language is best for getting job 2020?

0 Answers  


Explain what is dynamic data structure?

0 Answers  


Explain the concept and use of type void.

0 Answers  


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? ( >=, <=, <>, ==)

0 Answers  


what are bps & baud rates? differentiate these two?

2 Answers   TCS,


Categories