## Featured Replies in this Discussion

- by Narue
- by NarueAdak 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: ...

it's for my computing course at uni. i need to manipulate the number as an integer. simply just to show that i can. my ideas so far are to read them as seperate integers and them join them together some how though i'm not sure how to do that 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

OK so I have written the loop as recommended and I think its a great idea thank you but...

I seem to be stuck on how to remove the hyphen I am only aware of how to replace it and it wont let me replace it with nothing

Ives tried doing as many different thing as I could think of but to no avail.

I've included the code I have so far tried the things that haven't worked are commented out and I've included what the printout was

```
# include<stdio.h>
# include<string.h>
# include<stdlib.h>
int
main(int argc, char **argv){
char number[30] = "555-123-9876";
char number2[30];
int count;
for (count = 0; count < sizeof(number); count++)
{
//count = count + 1
if (number[count] == '-')
//if (number[count] != '-' && number[count] != ' ')
{
//number[count] = '\0'; // I end up with 555
//number2[count] = number[count]; // I end up with 555
//strcpy(number2, &number[count]); // I end up with 555-123-9876
}
}
printf("%s\n ", number);
return 0;
}
```

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.

No-one has to spend time they can't spare. I have been stuck on this all night. it's the last part on a much larger project.

I am trying. and not asking for handouts. I like the help I've received so far which is why I'm still here.

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;
}
```