Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #define MAX 50
- using namespace std;
- int main() // You are NOT allowed to change the main() function
- {
- char name[MAX+1];
- int getIndex(char[], char);
- ifstream myfile("customer.txt", ios::in);
- if (myfile.fail())
- {
- cerr << "Failed to open the file\n";
- return 1;
- }
- while (! myfile.eof())
- {
- myfile.getline(name, sizeof(name));
- cout << getIndex(name, 'A') << endl; // searching for the index of the > character “a”
- } // while
- myfile.close();
- return 0;
- } // main
- // Return the index where the character in the variable “what” is found > in the character array
- // Return -1, if the character in the variable “what” is NOT found in the > character array “s”.
- int getIndex(char s[], char what)
- {
- for(int i = 0; i <= strlen(s); i++)
- {
- char w = tolower(what);
- char c = tolower(s[i]);
- if(c == w)
- return i;
- }
- return -1;// <----- having problem with this search code. the professor said is a 10 min code, really easy but i spend the last 7 hours, googling and trying codes. it wont work.. please help.
- } // getIndex
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement