Take in the telephone number as a string.
Scan over the chars, and remove any hyphens or /'s.
If any char in the string is unwanted, then
for(each char from that point, to the (end -1) of the string) {
assign i+1 to i, in the array
}
and you're dancing on the ceiling. ;)
Adak
Posting Virtuoso
1,640 posts since Jun 2008
Reputation Points: 456
Solved Threads: 196
Skill Endorsements: 7
I am trying to take a user input phone number and perform calculations on it as an integer of type long long.
Why? To see if the phone number is prime? This makes no sense because a phone number isn't a number, per se.
WaltP
Posting Sage w/ dash of thyme
11,404 posts since May 2006
Reputation Points: 3,421
Solved Threads: 1,055
Skill Endorsements: 37
i thought that maybe there was a way to read it as a string skipping the hyphens then converting it to an integer which is what i tried to do above but can't get it right
Not really, but you can read as a string and remove the hyphens, as Adak mentioned.
WaltP
Posting Sage w/ dash of thyme
11,404 posts since May 2006
Reputation Points: 3,421
Solved Threads: 1,055
Skill Endorsements: 37
So much time wasted for such a simple task. I wonder if the OP really wants to do it and isn't just looking for a handout.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,483
Solved Threads: 1,407
Skill Endorsements: 54
Adak suggested one algorithm, but it's somewhat inefficient. Consider two pointers (or indices) into the string. One of them is the end of your result and the other walks along the original string and skips over hyphens. This is a common algorithm for removing whitespace, but it can be specialized to hyphens or even generalized:
char *remove_all(char *s, const char *match)
{
char *start = s;
char *p;
for (p = s; *s != '\0'; s++) {
if (strchr(match, *s) == NULL)
*p++ = *s;
}
*p = '\0';
return start;
}
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,483
Solved Threads: 1,407
Skill Endorsements: 54
Question Answered as of 1 Year Ago by
Narue,
WaltP
and
Adak