I am learning c++, and I am having issues doing some newbie things. I am trying to create a very small application that takes the users input and stores it into a char array. I then parse through that array and remove all parenthesis and dases and display it. like the following
(325)858-7455
to
3258587455
But I am getting errors
error C2440: '=' : cannot convert from 'const char [2]' to 'char'
Below is my simple code that can easily be thrown in a compiler and ran.
#include "stdafx.h"
#include<iostream>
#include<conio.h>
using namespace std;
/*
This is a template Project
*/
int main()
{
char phoneNum[25];
for(int i = 0; i < (sizeof(phoneNum) / sizeof(char)); i++)
{
phoneNum[i] = "i";
}
cout<< "Enter a phone Number" <<endl;
cin>>phoneNum;
if(phoneNum[0] != '(' || phoneNum[4] != ')' || phoneNum[8] != '-')
{
cout<<"error";
}
else
{
for(int i = 0; i < (sizeof(phoneNum) / sizeof(char));i++)
{
if(phoneNum[i] != '(' || phoneNum[i] != ')' || phoneNum[i] != '-')
{
cout<<phoneNum[i];
}
}
}
cin>>phoneNum;
getchar();
return 0;
}
It is not completely finished so if anyone has any pointers on the best way to remove strings characters from a string. that would be great.