OMG......I JUST DID IT!!!! IT PRINTS OUT THE CORRECT FORMAT!!!!!!! AHH I"M EXTREMELY HAPPY RIGHT NOW OMG. Okey, now I have to work on the loops for checking if the input is correct or not. I will post if I can't get it to work.
Thank You again so much!!!
and here's my working code:
Code:
#include <stdio.h>
/* forward declaration / prototype */
void remove_hyphen( char s[], char x );
void remove_left_paren( char s[], char f );
void remove_right_paren( char s[], char g );
int main ()
{
char s[50];
printf("Enter your phone number:\n");
scanf("%s", s);
printf( "Your phone number: %.13s\n", s );
remove_hyphen( s, '-' );
remove_left_paren(s, '(');
remove_right_paren(s, ')');
printf( "Formatted phone number: %.10s\n", s );
getchar();
return 0;
}
void remove_hyphen( char s[], char x )
{
int i, j;
for( i=0; s[i]!=0; ++i )
{
while(s[i]==x)
{
j=i;
while(s[j]!=0)
{
s[j]=s[j+1];
++j;
}
}
}
}
void remove_left_paren( char s[], char f )
{
int i, j;
for( i=0; s[i]!=0; ++i )
{
while(s[i]==f)
{
j=i;
while(s[j]!=0)
{
s[j]=s[j+1];
++j;
}
}
}
}
void remove_right_paren( char s[], char g )
{
int i, j;
for( i=0; s[i]!=0; ++i )
{
while(s[i]==g)
{
j=i;
while(s[j]!=0)
{
s[j]=s[j+1];
++j;
}
}
}
}