using namespace std;
int strLength(char *begin)
{
char *pch = begin;
int nCount = 0; //計字符數的變量
while (*pch != 0)
{ //發現'\0'則結束循環
pch++; //字符指針移向下壹位
nCount++;
}
return nCount;
}
int main()
{
int j, n;
char szArr[128][128];
cout << "輸入字符串個數: " ;
cin >> n;
for (j = 0; j < n; j++)
{
cin >> szArr[j];
}
int nMaxLength = 0;
int nMaxIndex = 0;
for (j = 0; j < n; j++)
{
if (nMaxLength < strLength(szArr[j]))
{
nMaxLength = strLength(szArr[j]);
nMaxIndex = j;
}
}
cout << "最長的字符串為:" << szArr[nMaxIndex] << endl;
cout << '\t' << "其長度為:" << nMaxLength << "個字符" << endl;
system("pause");
return 0;
}