A
ash
i am writing this program (for exercise1-9 in k&r-2nd edition) which
removes extra spaces in string
example- "test string" will be "test string"
#include<stdio.h>
#include<string.h>
#include<conio.h>
main()
{
char str[20],st[20];
int i=0,j=0;
printf("enter string");
gets(str);
while(str!=NULL)
{
if(str==' ')
{ st[j++]=st[i++];
while(str==' ') i++;
}
else
st[j++]=str[i++];
}
st[j]=NULL;
strcpy(str,st);
puts(str);
}
(compiled in turbo c++ for windows version 3.1)
i know there should be other ways to write this program (thats a bad
program ),can someone help me in writing that program in compact way
and give me some logic and tips.
i want to use gcc but i don`t have linux operating system and one
software which allows gcc compiling in windows (cygwin) is not working.
anyone can advice me such a program that allows compiling with gcc in
windows( this is off topic but advices are always welcome).
thankx
removes extra spaces in string
example- "test string" will be "test string"
#include<stdio.h>
#include<string.h>
#include<conio.h>
main()
{
char str[20],st[20];
int i=0,j=0;
printf("enter string");
gets(str);
while(str!=NULL)
{
if(str==' ')
{ st[j++]=st[i++];
while(str==' ') i++;
}
else
st[j++]=str[i++];
}
st[j]=NULL;
strcpy(str,st);
puts(str);
}
(compiled in turbo c++ for windows version 3.1)
i know there should be other ways to write this program (thats a bad
program ),can someone help me in writing that program in compact way
and give me some logic and tips.
i want to use gcc but i don`t have linux operating system and one
software which allows gcc compiling in windows (cygwin) is not working.
anyone can advice me such a program that allows compiling with gcc in
windows( this is off topic but advices are always welcome).
thankx