If you declare a string 32 bits long after you put thirty two bits in it it should only print those 32 bits correct???? It shouldn't print all these null characters then another 32 bit string??? sorry just venting a little
Printable View
If you declare a string 32 bits long after you put thirty two bits in it it should only print those 32 bits correct???? It shouldn't print all these null characters then another 32 bit string??? sorry just venting a little
>>sorry just venting a little
Is there a specific program you are having trouble with? If so post the code and we'll be more then happy to look it over...
>It shouldn't print all these null characters then another 32 bit string???
Not unless you are using a C string that you forgot to terminate with a nul character.
-Prelude
Yes, if you declare a string 32 elements long, you may access elements 0-31 (effectively 32 elements) You cannot access the 32nd element, as, in essence it's actually the 33rd element of your string. Remember, counting is zero-based.
char *pszString = { "Hello" };
pszString[0] now contains 'H'
pszString[1] = 'e'
pszString[2] = 'l'
pszString[3] = 'l'
pszString[4] = 'o'
pszString[5] = '\0' Null terminator, overwrite this and you'll overflow when attemping to print the string
OK here goes I am making a simulator and trying to make an and gate work in the ALU(I have the same problems with or gates, nor, etc)
The Output looks like this:Code:
void main()
{
//ALU
char CRYOUT = '0'; //Carry out flag
char OVF = '0'; //Overflow flag
char ZERO = '0'; //Zero flag
char SGN = '0'; //Sign bit that comes of ALU, MSB
//ALU controls
char CTLALU[5]; //Control ALU
char CTLCIN = '0'; //Carry in
char AluInputA[33]; //Output saved from MUXALUA and is input to ALU A
char AluInputB[33]; //Output saved from MUXALUB and is input to ALU B
char AluOutput[33]; //Output saved from the ALU
cout << "Testing ALU function." << endl;
ALU(AluInputA, AluInputB, CTLALU, CTLCIN, CRYOUT, OVF, ZERO, SGN, AluOutput);
cout << "And Output = " << AluOutput << endl;
}
//--------------------AND--------------------
void and(char InputA[33], char InputB[33], char Output[33])
{
for(int i = 31; i >= 0; i--)
{
if(InputA[i] == '1' && InputB[i] == '1')
Output[i] = '1';
else
Output[i] = '0';
}
}
The binary number in decimal is 0
4 to 1 Multiplexer = 00000000000000000000000000000010
MUXALUB
The binary number in decimal is 3
4 to 1 Multiplexer = 00000000000000000000000000001111
Enter in ALU Control: 0001
Testing ALU function.
The binary number in decimal is 1
Output: 00000000000000000000000000000010¨d¨d¨d¨d0000000000 0000000000000000001111
Press any key to continue
so as you see the first 32 bits is right but the other characters then InputB from the 4-1 mux is also in the string. I hope someone can help. Thanks.