I know how to test for a blank space,but how can you test for more than one blank ?

If you know how to test for one blank...then test for another one?

to test for two blanks in the middle of a string, use a byte compare. Don't use a string compare because it expects a null at the end of two blanks.

try this.I got correct ans
#include<stdio.h>
#include<string.h>
void main()
{
char x[25],a[10];
int i,p=0,l;
clrscr();
printf("enter name\n");
gets(x);
l=strlen(x);
for(i=0;i<l;i++)
if(x==32)
p++;
printf("space %d",p);
getch();
}

That is some of the worst code I've seen! 16 lines with the following problems:
1) void main() -- main is ALWAYS an int.
2) clrscr() -- no current compiler has this function and it's a bad idea to use it in the first place.
3) gets() -- the most dangerous input function ever written, can easily cause your program to crash
4) getch() -- another function that should not be used, very non-standard
5) no conio.h which is required for getch() and clrscr()
6) doesn't really find multiple (consecutive) spaces, only counts spaces
7) no CODE Tags

IOW, don't bother with the above post...

/* program tht replaces two or more consecutive blanks in a string by a single blank.. */
# include<stdio.h>
int main(){
int i;
char s[50],*p,*q;
printf("\n\n :");
gets(s);
 for(i=0;s[i];i++){
  if(s[i]==32){
     p=&s[i+1];
    while(*p && *p==32){
	  q=p;
	  while(*q){
	  *q=*(q+1);
	  q++;
	  }
     }
  }
 }
printf("\n\n :%s",s);
return 0;
}
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.