[algogeeks] Remove spaces

2011-08-12 Thread Raghavan
A huge paragraph has irregular spaces between the words, how to
effectively we can make everything to single space.


Example : My name   is xyz
Should to converted to : My name is xyz


-- 
Thanks and regards,
Raghavan.K.L
http://in.linkedin.com/in/raghavankl

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Remove spaces

2011-08-12 Thread sagar pareek
easy can be done in O(n) time and in O(1)

On Fri, Aug 12, 2011 at 3:47 PM, Raghavan its...@gmail.com wrote:

 A huge paragraph has irregular spaces between the words, how to
 effectively we can make everything to single space.


 Example : My name   is xyz
 Should to converted to : My name is xyz


 --
 Thanks and regards,
 Raghavan.K.L
 http://in.linkedin.com/in/raghavankl

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
**Regards
SAGAR PAREEK
COMPUTER SCIENCE AND ENGINEERING
NIT ALLAHABAD

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Remove spaces

2011-08-12 Thread sagar pareek
and in O(1) space

On Fri, Aug 12, 2011 at 3:53 PM, sagar pareek sagarpar...@gmail.com wrote:

 easy can be done in O(n) time and in O(1)


 On Fri, Aug 12, 2011 at 3:47 PM, Raghavan its...@gmail.com wrote:

 A huge paragraph has irregular spaces between the words, how to
 effectively we can make everything to single space.


 Example : My name   is xyz
 Should to converted to : My name is xyz


 --
 Thanks and regards,
 Raghavan.K.L
 http://in.linkedin.com/in/raghavankl

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 **Regards
 SAGAR PAREEK
 COMPUTER SCIENCE AND ENGINEERING
 NIT ALLAHABAD




-- 
**Regards
SAGAR PAREEK
COMPUTER SCIENCE AND ENGINEERING
NIT ALLAHABAD

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Remove spaces

2011-08-12 Thread ankit sambyal
void delExtraSpaces (char *Str)
{
int Pntr = 0;
int Dest = 0;
 int flag=0;
while (Str [Pntr])
{
if (Str [Pntr] != ' ')
{
  Str [Dest++] = Str [Pntr];
  flag=0;
}
else if(Str[Ptr]==' '   flag==1)
 Str [Dest++] = Str [Pntr];
else
 flag=1;
Pntr++;
}

Str [Pntr] = '/0';
}

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Remove spaces

2011-08-12 Thread sagar pareek
ankit.
flag ko wapis 0 kaun karega?
pehle code ko run karke check karna chahiye na.. !

mean multiple spaces jaruri nahi ki ek hi baar ho :P

On Fri, Aug 12, 2011 at 4:05 PM, ankit sambyal ankitsamb...@gmail.comwrote:

 void delExtraSpaces (char *Str)
 {
 int Pntr = 0;
 int Dest = 0;
  int flag=0;
 while (Str [Pntr])
 {
 if (Str [Pntr] != ' ')
 {
   Str [Dest++] = Str [Pntr];
   flag=0;
 }
 else if(Str[Ptr]==' '   flag==1)
  Str [Dest++] = Str [Pntr];
 else
  flag=1;
 Pntr++;
 }

 Str [Pntr] = '/0';
 }

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
**Regards
SAGAR PAREEK
COMPUTER SCIENCE AND ENGINEERING
NIT ALLAHABAD

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Remove spaces

2011-08-12 Thread saurabh singh
The code is buggy..

anyways the idea is to maintain two indexes one which points to the string
upto which spaces have been removed and one which travels with a constant
pace,,,

Kindly share the ideas with codesWriting code is a kid's affair.
On Fri, Aug 12, 2011 at 7:45 PM, sagar pareek sagarpar...@gmail.com wrote:

 ankit.
 flag ko wapis 0 kaun karega?
 pehle code ko run karke check karna chahiye na.. !

 mean multiple spaces jaruri nahi ki ek hi baar ho :P


 On Fri, Aug 12, 2011 at 4:05 PM, ankit sambyal ankitsamb...@gmail.comwrote:

 void delExtraSpaces (char *Str)
 {
 int Pntr = 0;
 int Dest = 0;
  int flag=0;
 while (Str [Pntr])
 {
 if (Str [Pntr] != ' ')
 {
   Str [Dest++] = Str [Pntr];
   flag=0;
 }
 else if(Str[Ptr]==' '   flag==1)
  Str [Dest++] = Str [Pntr];
 else
  flag=1;
 Pntr++;
 }

 Str [Pntr] = '/0';
 }

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 **Regards
 SAGAR PAREEK
 COMPUTER SCIENCE AND ENGINEERING
 NIT ALLAHABAD

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
Saurabh Singh
B.Tech (Computer Science)
MNNIT ALLAHABAD

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Remove spaces

2011-08-12 Thread sagar pareek
sorry
i missed the flag=0 in line 11...
but still ur code is not correct..

here is my code.
*
*

*#includestdio.h
#includestring.h

main()
{
 int i,l,j=0,count=0;
 char str[100]=hi!  howare you? I m fine   so say
whats goin  on???   :P;

 //printf(enter the string:- );
 //fgets(str,100,stdin);
 l=strlen(str);

 for(i=0;il;i++)
 {
if(str[i]!=' ')
{ str[j++]=str[i];  count=0; }

else if(str[i]==' '!count)
{ str[j++]=str[i]; count=1; }

 }
 str[j]='\0';
 printf 
http://www.opengroup.org/onlinepubs/009695399/functions/printf.html(New
string is :- %s\n,str);
}
 *



On Fri, Aug 12, 2011 at 7:45 PM, sagar pareek sagarpar...@gmail.com wrote:

 ankit.
 flag ko wapis 0 kaun karega?
 pehle code ko run karke check karna chahiye na.. !

 mean multiple spaces jaruri nahi ki ek hi baar ho :P


 On Fri, Aug 12, 2011 at 4:05 PM, ankit sambyal ankitsamb...@gmail.comwrote:

 void delExtraSpaces (char *Str)
 {
 int Pntr = 0;
 int Dest = 0;
  int flag=0;
 while (Str [Pntr])
 {
 if (Str [Pntr] != ' ')
 {
   Str [Dest++] = Str [Pntr];
   flag=0;
 }
 else if(Str[Ptr]==' '   flag==1)
  Str [Dest++] = Str [Pntr];
 else
  flag=1;
 Pntr++;
 }

 Str [Pntr] = '/0';
 }

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 **Regards
 SAGAR PAREEK
 COMPUTER SCIENCE AND ENGINEERING
 NIT ALLAHABAD




-- 
**Regards
SAGAR PAREEK
COMPUTER SCIENCE AND ENGINEERING
NIT ALLAHABAD

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Remove spaces

2011-08-12 Thread ankit sambyal
Guys sorry for posting the buggy code .  Here is the working code :

void delExtraSpaces (char Str[])
{
int Pntr = 0;
int Dest = 0;
 int flag=0;
while (Str[Pntr]!='\0')
{
if (Str[Pntr] != ' ')
{
  Str[Dest++] = Str[Pntr];
  flag=0;
}
else if(Str[Pntr]==' '   flag==0)
{
  Str[Dest++] = Str[Pntr];
  flag=1;
}

Pntr++;
}

Str[Dest] = '\0';
}

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.