前田稔(Maeda Minoru)の超初心者のプログラム入門
![]()
![]()
string s1,s2;
s1= "abc";
s2= "ABC";
if (s1==s2)
printf("s1 と s2 は等しい\n");
else
printf("s1 と s2 は等しく無い\n");
|
/*★ 大文字/小文字を区別しないで比較 前田 稔 ★*/
#include <stdio.h>
#include <string>
using namespace std;
// 1文字の比較
bool ciChar(char c1, char c2)
{
return tolower(static_cast |
// 文字列が等しいとき true を返す
bool StrComp(const string s1, const string s2)
{ unsigned len,i;
len = s1.size();
if (len!=s2.size()) return false;
for(i=0; i<len; i++)
{ if (ciChar(s1.at(i),s2.at(i))) return false;
}
return true;
}
int main()
{ string s1,s2;
s1= "abc";
s2= "ABC";
if (StrComp(s1,s2)) printf("%s == %s\n",s1.c_str(),s2.c_str());
else printf("%s != %s\n",s1.c_str(),s2.c_str());
s2= "Abc";
if (StrComp(s1,s2)) printf("%s == %s\n",s1.c_str(),s2.c_str());
else printf("%s != %s\n",s1.c_str(),s2.c_str());
return 0;
}
|
![]()