pr0810.cpp
来自「practice c++, it is from the book http:/」· C++ 代码 · 共 33 行
CPP
33 行
// Programming with C++, Second Edition, by John R. Hubbard
// Copyright McGraw-Hill, 2000
// Problem 8.10 on page 203
// A strchr() function
#include <iostream>
using namespace std;
char* Strrchr(const char* s, int c);
// returns a pointer to the last occurrence of c in s;
void test(char* s, char c);
// tests the Strrchr() function;
int main()
{ test("ABCABC",'C');
test("ABCABC",'D');
}
char* Strrchr(const char* s, int c)
{ const char* pp=0;
for (const char* p=s; p && *p; p++)
if (*p==c) pp = p;
return (char*)pp;
}
void test(char* s, char c)
{ char* p=Strrchr(s,c);
cout << "Strchr(\"" << s << "\",\'" << c << "\') = ";
if (p) cout << "s[" << p - s << "] = " << *p << endl;
else cout << "NULL" << endl;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?