I
Interrupt
Hi folks I’m working though some exercise trying to teach myself C,
I’m having problem with a function I’ve written. It takes and array
and removes the white spaces. I’m having problems with logic
operations within loops.
My first problem is once If statement executes and “i” is incremented
the else statement doesn’t execute again!! WHY???
*****************************CODE********************************************
/* copy: copy 'from' into 'to'removing white space */
void copy(char to[], char from[], int maxi)
{
int i;
for(i=0;i<=maxi;++i)
{
if(from==' ' || from=='\0' || from=='\t'|| from
=='\n')
{
to = from[i+1]; // if there is white space copy
the next value
i++; //>>>>>>>>>>>>>>>>>>>> problems start here
}
else
{
to = from; // if no white space copy
}
}
}
********************************CODE******************************************
So I thought I’d approach the problem from the opposite angle if it’s
not white space, but the if statement executes whether there is white
space or not…..WHY???
********************************CODE2*****************************************
/* copy: copy 'from' into 'to'removing white space */
void copy(char to[], char from[], int maxi)
{
int i;
for(i=0;i<=maxi;++i)
{
if(from!=' '||from!='\0'||from!='\t'||from!='\n') {
to = from; // if no white space
copy
}
else
{
to = from[i+1]; // if there is white space copy the
next value
i++;
}
}
}
**************************************CODE2*************************************
I’m having problem with a function I’ve written. It takes and array
and removes the white spaces. I’m having problems with logic
operations within loops.
My first problem is once If statement executes and “i” is incremented
the else statement doesn’t execute again!! WHY???
*****************************CODE********************************************
/* copy: copy 'from' into 'to'removing white space */
void copy(char to[], char from[], int maxi)
{
int i;
for(i=0;i<=maxi;++i)
{
if(from==' ' || from=='\0' || from=='\t'|| from
=='\n')
{
to = from[i+1]; // if there is white space copy
the next value
i++; //>>>>>>>>>>>>>>>>>>>> problems start here
}
else
{
to = from; // if no white space copy
}
}
}
********************************CODE******************************************
So I thought I’d approach the problem from the opposite angle if it’s
not white space, but the if statement executes whether there is white
space or not…..WHY???
********************************CODE2*****************************************
/* copy: copy 'from' into 'to'removing white space */
void copy(char to[], char from[], int maxi)
{
int i;
for(i=0;i<=maxi;++i)
{
if(from!=' '||from!='\0'||from!='\t'||from!='\n') {
to = from; // if no white space
copy
}
else
{
to = from[i+1]; // if there is white space copy the
next value
i++;
}
}
}
**************************************CODE2*************************************