How to pass string(arr) to function and perform operation.
i m receiving an error:
....main.cpp|35|error: cannot convert 'std::string' to 'char*' for argument '1' to 'int check(char*)'|
Code:#include <iostream> #include <string> #include <stdlib.h> using namespace std; int check(char *arr); int main() { string arr; int cont=1; int chck; while (1) { cout << "Enter your Date of Birth (Format: DD/MM/YYYY e.g: 11/09/1984): "; getline(cin,arr); if (arr == "0") { cout << "Thankyou for using... :)"; exit(1); } else { if (arr.length() != 10 ) { cout << "Syntax Error! Please follow the syntax\n\n"; continue; } if(check(arr) != 0) // Checking the Syntax { if (check(arr) == 1) { cout << "\nError in Date. Please try again and follow the syntax\n"; } if (check(arr) == 2) { cout << "\nError in Month. Please try again and follow the syntax\n"; } if (check(arr) == 3) { cout << "\nError in Year. Please try again and follow the syntax\n"; } if (check(arr) == 4) { cout << "\nError in Syntax. Please try again and follow the syntax\n"; } cont=1; } } } return 0; } int check(char arr[10]) { if ((int)arr[0] <= 47 || (int)arr[0] >= 50 || (int)arr[1] <= 47 || (int)arr[1] >= 57 ) { return 1;// Date problem } if ( (int)arr[3] == 47 && (int)arr[4] <= 48 || (int)arr[4] >= 57) { return 2; // month problem } if( (int)arr[3] == 48 && (int)arr[4] <= 47 || (int)arr[4] >= 49) { return 2; // month problem } if( (int)arr[6] <= 48 || (int)arr[6] >= 49) { return 3; // Year problem } if( (int)arr[2] == '/' && (int)arr[5] == '/') { return 4; } return 0; }



2Likes
LinkBack URL
About LinkBacks



