Home > Back-end >  C character pointer
C character pointer

Time:04-19

#include
#include
using namespace std;

Int main ()
{
Char * bi;
Bi="01010101";
Int ten=0, I, j=7;
Char bin [9].
for(i=0; i<8; I++)
{
Bin [I]=* bi++;
If (bin [I]==1)
{
Ten +=pow (2, j);
}
J -;
}
Cout}

Want to know how to put the Numbers assigned to * bi, I wrote this bin [I] are the values of the characters' 0 'and' 1 'ASCALL code

There is why I put assigned to a string pointer has the following warning, you can't?

[Warning] deprecated conversion from a string constant to 'char *' [- Wwrite - strings]

CodePudding user response:

Define a const char * bi;

CodePudding user response:

reference 1st floor maguangzhi response:
define const char * bi;

Define a const or calculate ASCALL yards

CodePudding user response:

Reference:
 # include 
#include
using namespace std;

Int main ()
{
Char * bi;
Bi="01010101";
Int ten=0, I, j=7;
Int bin [9].//char bin [9].
for(i=0; i<8; I++)
{
Bin [I]=* (bi++) - '0'.
If (bin [I]==1)
{
Ten +=pow (2, j);
}
J -;
}
Cout
}

CodePudding user response:

In addition to the above, you can also use the
If (bin [I]=='1')

CodePudding user response:

The
reference 3 floor QZJHJXJ response:
for reference:
 # include 
#include
using namespace std;

Int main ()
{
Char * bi;
Bi="01010101";
Int ten=0, I, j=7;
Int bin [9].//char bin [9].
for(i=0; i<8; I++)
{
Bin [I]=* (bi++) - '0'.
If (bin [I]==1)
{
Ten +=pow (2, j);
}
J -;
}
Cout
}
understand thank you, that the string assigned to a pointer character why there will be a warning, you can't

CodePudding user response:

reference rogue 4 floor response:
in addition to the above, you can also use the
If (bin [I]=='1')
thanks ~
  • Related