G
G
Gagatyn2017-11-13 01:09:19
MySQL
Gagatyn, 2017-11-13 01:09:19

How to store characters in an int array?

Hello!
Here is the code below. How to keep characters in int array after input? Is it possible? Is this correct or do I need to create a 2nd char array?

#include "stdio.h"

int main() {
  int i, j, a[9][9], c = 1, n = 5, x = 0;
  for (i = 0; i < 9; i++) {
    for (j = 0; j < 9; j++) {
      a[i][j] = c++;
      printf("%0.2d ", a[i][j]);
    } 
    printf("\n");
  }
  
  while(n>0) {
    printf("Input number: ");
    scanf("%d", &x);
    for (i = 0; i < 9; i++) {
      for (j = 0; j < 9; j++) {
        if(a[i][j] == x) {
          a[i][j] = 'P';
          printf("(%c) ", a[i][j]);
          continue;
        }
        printf("%0.2d ", a[i][j]);
      } 
      printf("\n");
    }
    n--;
  }
  return 0;
}

Answer the question

In order to leave comments, you need to log in

5 answer(s)
V
Vitaly Karasik, 2019-08-21
@vitaly_il1

one.

the request is executed in 22ms:
- I would test a more realistic scenario - how long does XX queries take - eg with https://dev.mysql.com/doc/refman/8.0/en/mysqlslap.html
2. How many indexes are on this table?
3.
CentOS, AMD 8 cores (don't remember the model), 64 GB RAM, SSD disks
- what is innodb_buffer_pool_size?
4. let's check the runtime with "insert" instead of update

A
Alexey Kostin, 2019-08-21
@rumanzo

set syn_binlog=0 and innodb_flush_log_at_trx_commit=2.
Please report the result.

V
Vlad, 2019-08-22
@p1rat495

Look at the connection to the database. Alternatively, connect to it by ip if you connect through the hostname

D
Dmitry T., 2019-08-29
@tyzhnenko

Have you tried different IO schedulers?
If there is a swap on the server, how many mysql pages are in the swap? Have you tried to test with the swap turned off?

I
Ivan Klimenko, 2017-11-13
@yeswell

Yes, you can do that, because it charis also an integer data type. And the variable stores the symbol number in the symbol table. Accordingly, in order to use these values ​​as symbols later, you need to convert them to the char.
Here is an example:

#include <iostream>

using namespace std;

int main()
{
    int i;
    char c;

    cin >> i;
    cin >> c;

    cout << i << endl;
    cout << c << endl;

    i = c;

    cout << i << endl;
    cout << char(i) << endl;
  
    return 0;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question