Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

changing array

Status
Not open for further replies.

pqe

Technical User
Nov 14, 2005
2
MY
Hi,

I have a problem that has been bugging me for days

i have 2 arrays
A=[GGGGG GG GGGG GG GGGGG G G G ]
B=[10101100010101010101010101010110]

both are same in length

i need to change Array B in such a way that when Array A has a blank, the same position in Array B changes into character 'P'
below are my codes,this is a subroutine and arrays are predefined


int ABC()
{
int i;

for (i=0;i<=32;i++)
{if A = " "
(B = "P";)
}

}


Is there anything wrong with the logic or syntax? Pls help. thanks.
 
oh yea...correct A == " ", thanks!
can any1 spot anything else? thanks.
 
Wrong! Do it again!

It should be

Code:
if ( A[i] == ' ' )

' ' is a single space character
" " is a space character followed by a null.
i.e. it's a string.
 
First issue is the "i<=32".
Do you really want to check 33 characters?
I guess you actually wanted 32. In that case use "i<32".
Next issue is the comparison. Never use "=" for comparison. ALWAYS use "==" for comparison.
Third issue, a character is wrapped in single quotes, not double quotes. Double quotes is for multi-character strings.
Fourthly, if a function is defined as returning an int it MUST have a return statement.
Therefore:
Code:
int ABC(char *A, char *B)
{
  int i;

  for (i=0;i<=32;i++)
  {
    if(A[i] == ' ') {
      B[i] = "P";
    }
  }
}



Trojan.
 
A last issue is that the P assignment should be like this:
Code:
B[i] = [blue]'[/blue]P[blue]'[/blue];
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top