i have to creat a program that verifes a valid user id before printing out the new email address. here are my errors:
c:\users\rena0514\documents\visual studio 2005\projects\user_id\user_id\verification.cpp(50) : error C2664: 'strncpy' : cannot convert parameter 2 from 'std::string' to 'const char *'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>c:\users\rena0514\documents\visual studio 2005\projects\user_id\user_id\verification.cpp(66) : error C2664: 'isalpha' : cannot convert parameter 1 from 'char *' to 'int'
1> There is no context in which this conversion is possible
here is my code:
#include <iostream>
#include <string>
using namespace std;
bool user_ID_length(char*, int);
bool user_ID_alpha(char*);
bool user_ID_num(char*, int);
bool user_ID_special(char*, int);
int main()
{
char userId[35];
string email_address="@mvsu.edu";
int length;
cout<<"Create a user ID: ";
cin.getline(userId,20);
length = (long)strlen(userId);
do
{
cout<<endl<<"Invalid. User Id must be at least 6 digits. Retry:";
cin.getline(userId, 20);
length = (long)strlen(userId);
}while(user_ID_length==false);
do
{
cout<<endl<<"Invalid. User Id must begin with a letter. Retry: ";
cin.getline(userId, 20);
}while(user_ID_alpha==false);
do
{
cout<<endl<<"Invalid. User Id must contain 1 number. Retry: ";
cin.getline(userId, 20);
}while(user_ID_num==false);
do
{
cout<<endl<<"Invalid. User Id cannot contain a special character. Retry: ";
cin.getline(userId, 20);
}while(user_ID_special==false);
strncpy(userId, email_address, 9);
cout<<"Your new email address is"<<userId;
return 0;
}
bool user_ID_length(char* userId, int length)
{
if(length<=5)
return false;
else
return true;
}
bool user_ID_alpha(char* userId)
{
if(!isalpha(userId))
return false;
else
return true;
}
bool user_ID_num(char* userId, int length)
{
bool results = false;
for(int i=0; i<length; i++)
{
if(isdigit(userId[i]))
results = true;
else
return false;
}
return results;
}
bool user_ID_special(char* userId, int length)
{
bool results = false;
for(int i=0; i<length; i++)
{
if(!ispunct(userId[i]))
results = true;
else
return false;
}
return results;
}