i have to write a program that deletes special characters from a phone number. For Example:
(0049)5599/85675-344
0049559985675344

i have started to program it, but it doesn't seem to function. here's my code:

#include <stdio.h>

void affe(char nummer[]){
	int n , i, z;
	n = strlen(nummer) - 1;
	for (i = 0; i <= n; i++){
		if (nummer[i] < 0 && nummer[i] > 9){
			for(z = i; z <= n; z++){
				nummer[z] = nummer[z + 1];
			}
			n--;
		}
	}
}


int main (){
	char nummer[50];
	gets(nummer);
	affe(nummer);
	printf("%s", nummer);
	fflush(stdin);
	getchar();
	return 0;
}

can some1 help me???

i have to write a program that deletes special characters from a phone number. For Example:
(0049)5599/85675-344
0049559985675344

i have started to program it, but it doesn't seem to function. here's my code:

#include <stdio.h>

void affe(char nummer[]){
	int n , i, z;
	n = strlen(nummer) - 1;
	for (i = 0; i <= n; i++){
		if (nummer[i] < 0 && nummer[i] > 9){
			for(z = i; z <= n; z++){
				nummer[z] = nummer[z + 1];
			}
			n--;
		}
	}
}


int main (){
	char nummer[50];
	gets(nummer);
	affe(nummer);
	printf("%s", nummer);
	fflush(stdin);
	getchar();
	return 0;
}

can some1 help me???

Now consider your code:-

if (nummer[i] < 0 && nummer[i] > 9){

Now according to me since this is a char array, you numbers will be stored as chars and hence you will need to check for their ASCII equivalent values, or better you could just use the isdigit() function, to figure out if the current character is a valid digit or not.

n = strlen(nummer);
for (int i = 0; i < n; i++) {
    if (nummer[i] <= '0' || nummer[i] >= '9') {
        for(int j = i; j < n; j++){
        nummer[j] = nummer[j + 1];
    ...

thanx arkM!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.