Program in C - help needed

No.11227586 ViewReplyOriginalReport
I have to remove all punctuation marks from a string and if there is only 1 punctuation mark there should be space (example rrr.rr should be rrr rr) and if there is more then 1 punctuation mark then but a number(example rrr.,..rr should be rrr4rr)

This examples is good:

input jks6X7hs__xXxJK!jsX...YKY7,;,shhhXsHXSh__!..x

output: jks6X7hs2xXxJK jsX3YKY73shhhXsHXSh5x

But these examples wont work properly

input: __

Output: 2

input: _X_X_X_X_

output: X X X X

And this is my code:

int n=strlen(p);
int increment=0;
int i, counter=0;

for(i=0;i<n;i++)
{
if(!(p>='0' && p<='9') && !(p>='a' && p<='z') && !(p>='A' && p<='Z')) {

counter=0;
while(!(p>='0' && p<='9') && !(p>='a' && p<='z') && !(p>='A' && p<='Z'))
{
i++;
counter++;
}
i--;

if(counter==1)
{
p[increment++]=' ';
}
else{

p[increment++]=counter+'0';
}
}
else{
p[increment++]=p;
}

}
p[increment]=0;