-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathManu-Question1.CPP
More file actions
50 lines (47 loc) · 968 Bytes
/
Manu-Question1.CPP
File metadata and controls
50 lines (47 loc) · 968 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream.h>
#include <stdio.h>
#include <string.h> //wrong spelling
#define len strlen //to change len to strlen
int getFIndex(char[],char); //FUNCTION DEFINTIONS
int getLIndex(char[],char);
int main()
{
char str[100];
char ch;
int Lindex,Findex;
gets(str); //missing ; and need gets
cin>>ch;
Lindex = getLIndex(str,ch);
Findex= getFIndex(str,ch);
if(Lindex!=-1)
cout<<Findex<<endl<<Lindex;
else
cout<<"NOT FOUND"<<endl;
return 0;
}
int getFIndex(char string[100],char c) //need char array and function name was interchanged
{
int size = len(string),i=0;
while(i<size)
{
if(string[i]==c){ //== needed
return i;
break;
}
i++;
}
}
int getLIndex(char string[100],char c) //missing data type and function name changed
{
int size = len(string);
int i=size;
while( i>=0) //extra ;
{
if(string[i]==c){
return i;
break;
}
i--;
}
return -1; //not found case
}