1.c函数中变量的定义必须在函数前面全部定义完成,而c++则可在函数中间用到变量的时候再定义;
////////C函数
char hostname[128];
char *temp_info;
struct hostent *pHostent;
struct sockaddr_in sa;
gethostname(hostname, sizeof(hostname));
pHostent = gethostbyname(hostname);
memcpy(&sa.sin_addr.s_addr,pHostent->h_addr_list[0],pHostent->h_length);
temp_info=inet_ntoa(sa.sin_addr);
strcpy(info->local_PIPA,temp_info);
//////////C++函数
char hostname[128];
char *temp_info;
gethostname(hostname, sizeof(hostname));
struct hostent *pHostent = gethostbyname(hostname);
struct sockaddr_in sa;
memcpy(&sa.sin_addr.s_addr,pHostent->h_addr_list[0],pHostent->h_length);
temp_info=inet_ntoa(sa.sin_addr);
strcpy(info->local_PIPA,temp_info);
2.关于结构的定义
c定义为:struct hostent *pHostent;
c++定义为:hostent *pHostent;