C++ 新手在这里。编写一个简单的程序。一切正常,除了当我尝试提取名字和姓氏并单独打印它们时,姓氏中打印的字母数量将始终与名字中的数字大小相同。所以如果名字是 will jackson,程序会打印 firstname as: will 和 second name as: jack。我该如何解决这个问题?
这是代码
for( i = 0; i < 19; i++)
if(cAddress[i] == ' ' || cAddress[i] == '_' || cAddress[i] == '-' || cAddress[i] == '.')
break;
strncpy(cFirst, cAddress, i);
cFirst[i] = '\0';
cout << endl << "\n";
cout << "Your first name is " << cFirst << endl;
strcpy(cSur,cAddress + i + 1);
cSur[i] = '\0';
cout << endl;
cout << "Your surname is " << cSur << endl;