M
msundaram.visvanathan
Hi,
i tried to write this small code in C which would:
Input :a b c d
Output:abcd
code:
#include<stdio.h>
void main()
{
char t[]="a b c d";
char *q,*r;
int count=0;
q=t;
r=t;
printf("\ninput %s",t);
while(*q!='\0')
{
if(*q!=' ' && r!=q )
{
*r=*q;
*q=' ';
r=q;
continue;
}
else if(*q==' ')
{
q++;
continue;
}
else if(*q!=' ')
{
q++;
r++;
}
}
printf("\noutput %s",t);
}
With this I get :
input:a b c d
output:abc d
please provide your comments on what could be wrong.
Sundar.
i tried to write this small code in C which would:
Input :a b c d
Output:abcd
code:
#include<stdio.h>
void main()
{
char t[]="a b c d";
char *q,*r;
int count=0;
q=t;
r=t;
printf("\ninput %s",t);
while(*q!='\0')
{
if(*q!=' ' && r!=q )
{
*r=*q;
*q=' ';
r=q;
continue;
}
else if(*q==' ')
{
q++;
continue;
}
else if(*q!=' ')
{
q++;
r++;
}
}
printf("\noutput %s",t);
}
With this I get :
input:a b c d
output:abc d
please provide your comments on what could be wrong.
Sundar.