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 the structure pointer?
what is the output of the below code? main( ) { printf ( "\nOnly stupids use C?" ) ; display( ) ; } display( ) { printf ( "\nFools too use C!" ) ; main( ) ; }
why do some people write if(0 == x) instead of if(x == 0)?
What is wild pointer in c?
Write a program that receives as input a number omaadel-n-print, four digits.
What is the difference function call by value & function call by reference?
How can I convert integers to binary or hexadecimal?
Given a string write a program to print all alphabetical characters in the order of their occurance first,followed by the sum of the numeric characters then followed by the special characters in the order of their occurance.
1 Answers College School Exams Tests, Wipro,
Write a C program to perform some of the operation which can be performed using Single linked list
long int size a) 4 bytes b) 2 bytes c) compiler dependent d) 8 bytes
18 Answers Acropolis, HCL, Intel, TCS,
What is the difference between union and anonymous union?
How the c program is executed?