Remove characters from array(0-9)

flavius doroftei (10)
hello, i kept trying to figure out a function to remove digits from a char array, any help ?! ^^

this is what i have so far.

1
2
3
4
5
6
7
8
9
void elimnation(char arr[], char arr1[]) 
{
 int aux, l1;
 for(l1=0 ; arr[l1]!=0 ; l1++);
 for(i=0 ; i<l1 ; i++)
  if(arr[i]=<'0' && arr[i]>='9');
  arr1[i]=arr[i];
  puts(arr1);
}
AleaIactaEst (99)
This doesn't look bad so far, but what you probably want to do is to use another counter that counts the number of elements inserted into the arr1 array. Ex.:

1
2
3
4
5
6
7
8
int inserted = 0;

[...]

  if(arr[i]<'0' || arr[i]>'9') {  //<- removed semicolon here, changed && to ||, changed =< to <, >= to >
      arr1[inserted]=arr[i];
      inserted += 1;
  }


(This is probably what you wanted to use the aux variable for)
flavius doroftei (10)
Yes, that is why i needed the aux var for.

1
2
3
4
5
6
7
8
9
10
11
12
13
void elimnation(char sir1[], char sir2[])
{
	int l1, l2, i;
	int aux = 0;
	for(l1=0 ; sir1[l1]!=0 ; l1++);
	for(l2=0 ; sir2[l2]!=0 ; l2++);
	for(i=0 ; i<l1 ; i++)
	if(sir1[i]<'0' || sir1[i]>'9')
	{
		sir2[aux]=sir1[i];
		aux += 1;
	}
}


//sir=array (in my native language)
//Thank you very much, your idea
//totally worked, i really appreciate.
//
//It works now ! :D thank you again.
Last edited on
Registered users can post here. Sign in or register to post.