为什么strcmp函数总是
大家好,我是C++初学者,请个位专家,前辈门指点一下.
本程序的目的是输入5个学生姓名,急手机号,然后输入学生姓名,如果存在,则输出手机号
#include<iostream>
#include<string>
using namespace std;
int main()
{
int i,k;
cout<<"Please input student's names:"<<endl;
char name[5][30],number[5][10];
for(i=0;i<5;i++)
{
cout<<"input name["<<i+1<<"]:"<<endl;
cin>>name[i];
}
cout<<"Please enter the phone's number of all students:"<<endl;
for(i=0;i<5;i++)
{
cout<<"please enter "<<name[i]<<"'s number:"<<endl;
cin>>number[i];
}
char find[30];
cout<<"please input the student's name:"<<endl;
cin>>find[30];
for(i=0;i<5;i++)
{
char str[30];
strcpy(str,name[i]);
if(strcmp(str,find)==0)
{
cout<<number[i]<<" 's hpone number is:"<<endl;
break;
}
else
{
cout<<"name error!";
break;
}
}
return 0;
}