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
Nearly a Posting Virtuoso
1,479 posts since Jun 2008
Reputation Points: 425
Solved Threads: 185
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
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
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 andremove the hyphens, as Adak mentioned.
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
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,464
Solved Threads: 1,401
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,464
Solved Threads: 1,401