/*
*对于同名函数,编译器根据参数个数和参数类型对函数名进行扩展,从而对应不同的函数入口地址。
*/
#include <iostream>
using namespace std;
int compare(int ia, int ib);
int compare(char c1, char c2);
int compare(char *s1, char *s2);
// void compare(int i, j); // 重定义错误!同int compare(int ia, int ib);只有返回值不同,扩展后的函数名相同。
void display(int flag, char *ptr1, char *ptr2);
 
int main(int argc, char **argv)
{
   int ia = 0, ib = 0;
   char c1 = '\0', c2 = '\0';
   char s1[10] = {0, }, s2[10] = {0,};
   char buffer1[10] = {0, }, buffer2[10] = {0,}; // 存放由实参转换而来的字符串
   
   cout << "input two integers: " << endl;
   cin >> ia >> ib;
   // do not do any detection for input data to make it easy 
   sprintf(buffer1, "%d", ia); // integer to string fomat
   sprintf(buffer2, "%d", ib);
   display(compare(ia, ib), buffer1, buffer2);
   cout << "input two characters: " << endl;
   cin >> c1 >> c2;
   // do not do any detection for input data to make it easy 
   sprintf(buffer1, "%c", c1); // character to string fomat
   sprintf(buffer2, "%c", c2);
   display(compare(c1, c2), buffer1, buffer2);
   cout << "input two strings(the legth should be both less than 10): " << endl;
   cin >> s1 >> s2;
   // do not do any detection for input data to make it easy 
   sprintf(buffer1, "%s", s1); 
   sprintf(buffer2, "%s", s2);
   display(compare(s1, s2), buffer1, s2);
   system("pause");
   return 0; 
}
int compare(int ia, int ib)
{
   return (ia - ib);
}
int compare(char c1, char c2)
{
   return (c1 - c2);
}
int compare(char *s1, char *s2)
{
   return (strcmp(s1, s2));
}
void display(int flag, char *ptr1, char *ptr2)
{
   if (flag > 0)
    cout << ptr1 << " is larger than " << ptr2 <<endl;
   else if (flag < 0)
    cout << ptr1 << " is less than " << ptr2 << endl;
   else
    cout << ptr1 << " is equal to " << ptr2 << endl;
}