int main(void) { int index; char* inputString; char* target; inputString = malloc(sizeof(char)*50); printf("Enter a string: "); scanf("%s", inputString); printf("You typed: \'%s\'\n", inputString); printf("Enter an index: "); scanf("%d", &index); printf("The index entered is: %d\n", index); target = getCharAtIndex(inputString, index); printf("The memory address pointed at by target is: %p\n", target); printf("The address of target is: %p\n", &target); printf("The character that is pointed at by target is: %c\n", *target); return 0; }
void XlinkPreview::tileUpdated(int tileIndex) { if(!isConnected()) return; auto state = State::getInstance(); State::TileProperties properties = state->getTileProperties(); int charIndex = state->getCharIndexFromTileIndex(tileIndex); int numChars = properties.size.width() * properties.size.height(); if(properties.interleaved == 1) { xlink_load(0xb7, 0x00, 0x3000 + charIndex * 8, (uchar*) state->getCharAtIndex(charIndex), numChars*8); } else { for(int sent=0; sent<numChars; sent++) { xlink_load(0xb7, 0x00, 0x3000 + charIndex * 8, (uchar*) state->getCharAtIndex(charIndex), 8); charIndex += properties.interleaved; } } }
void CharsetWidget::paintEvent(QPaintEvent *event) { QPainter painter; painter.begin(this); painter.fillRect(event->rect(), QWidget::palette().color(QWidget::backgroundRole())); painter.setBrush(QColor(0,0,0)); painter.setPen(Qt::NoPen); auto state = State::getInstance(); int end_x = 8; int pixel_size_x = _pixelSize.width(); int increment_x = 1; int bits_to_mask = 1; if (state->shouldBeDisplayedInMulticolor()) { end_x = 4; pixel_size_x = _pixelSize.width() * 2; increment_x = 2; bits_to_mask = 3; } QPen pen; pen.setColor({149,195,244,255}); if (hasFocus()) pen.setWidth(3); else pen.setWidth(1); pen.setStyle(Qt::PenStyle::SolidLine); for (int w=0; w<COLUMNS; w++) { for (int h=0; h<ROWS; h++) { int index = w + h * COLUMNS; quint8* charPtr = state->getCharAtIndex(index); for (int y=0; y<8; y++) { char letter = charPtr[y]; for (int x=0; x<end_x; x++) { // Warning: Don't use 'char'. Instead use 'unsigned char'. // 'char' doesn't work Ok with << and >> // only mask the bits are needed unsigned char mask = bits_to_mask << (((end_x-1)-x) * increment_x); unsigned char color = letter & mask; // now transform those bits into values from 0-3 since those are the // possible colors int bits_to_shift = (((end_x-1)-x) * increment_x); int color_pen = color >> bits_to_shift; if (!state->shouldBeDisplayedInMulticolor() && color_pen ) color_pen = State::PEN_FOREGROUND; painter.setBrush(Palette::getColorForPen(color_pen)); painter.drawRect((w*end_x+x) * pixel_size_x + OFFSET, (h*8+y) * _pixelSize.height() + OFFSET, pixel_size_x, _pixelSize.height()); } } painter.setPen(Qt::NoPen); } } if (_selecting) { pen.setColor({149,195,244,255}); painter.setPen(pen); painter.setBrush(QColor(149,195,244,64)); painter.drawRect(_cursorPos.x() * 8 * _pixelSize.width() + OFFSET, _cursorPos.y() * 8 * _pixelSize.height() + OFFSET, _selectingSize.width() * 8 * _pixelSize.width(), _selectingSize.height() * 8 * _pixelSize.height()); } else { pen.setColor({149,195,244,255}); painter.setPen(pen); painter.setBrush(QColor(128,0,0,0)); painter.drawRect(_cursorPos.x() * 8 * _pixelSize.width() + OFFSET, _cursorPos.y() * 8 * _pixelSize.height() + OFFSET, 8 * _pixelSize.width(), 8 * _pixelSize.height()); } paintFocus(painter); painter.end(); }