I need help solving this problem in my mind so if anyone had a similar problem it would help me a lot.
The task is:Enter an array of strings from the standard input, using the function invert
to invert each string. The inverted string must not contain digits.
Prototype function is: invert(char **array,int n);
Here' s my code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void processing_string(char *s);
void invert(char **array,int n)
{
if(n>0)
{
processing_string(array[n-1]);
invert(array,n-1);
}
}
void processing_string(char *s)
{
int d=strlen(s);
for(int i=0;i<d/2;i++)
{
char c=s[i];
s[i]=s[d-i-1];
s[d-i-1]=c;
}
char *t=(char*)calloc(d+1,sizeof(char));
for(int i=0,j=0;i<d;i++)
{
if(s[i]>='0' && s[i]<='9')
{
t[j++]=s[i];
}
}
strcpy(s,t);
free(t);
}
int main()
{
int n;
printf("n=");
scanf("%d",&n);
char *array[n][20];
for(int i=0;i<n;i++)
{
scanf("%s",array[i][20]);
}
invert(array,n);
for(int i=0;i<n;i++)
{
printf("%s",array[i][20]);
}
return 0;
}
The problem is that my program breaks, after entering the strings, I don't think I'm entering the strings as I should, and I'm not forwarding them well to the invert function?
Thanks in advance !
Best regards!