I want print table of ascii symbols like this:
0 1 2 3 4 5 6 7 8 9 a b c d e f
0
1
2 ! " # $ % & ' ( ) * + , - . /
3 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
4 @ A B C D E F G H I J K L M N O
5 P Q R S T U V W X Y Z [ \ ] ^ _
6 ` a b c d e f g h i j k l m n o
7 p q r s t u v w x y z { | } ~
8 � � � � � � � � � � � � � � � �
9 � � � � � � � � � � � � � � � �
a � � � � � � � � � � � � � � � �
b � � � � � � � � � � � � � � � �
c � � � � � � � � � � � � � � � �
d � � � � � � � � � � � � � � � �
e � � � � � � � � � � � � � � � �
f � � � � � � � � � � � � � � � �
I wrote this c code:
#include <stdio.h>
int main() {
char s[34] = " 0 1 2 3 4 5 6 7 8 9 a b c d e f\n";
printf("%s", s);
for (size_t i = 0; i < 16; ++i) {
char str[34];
char hex[2];
snprintf(hex, sizeof(hex), "%x", (int)i);
str[0] = hex[0];
for (size_t j = 0; j < 16; ++j) {
str[2 * j + 1] = ' ';
str[2 * j + 2] = i * 16 + j;
}
str[33] = '\0';
printf("%s\n", str);
}
}
It prints this:
0 1 2 3 4 5 6 7 8 9 a b c d e f
0
1
! " # $ % & ' ( ) * + , - . /
3 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
4 @ A B C D E F G H I J K L M N O
5 P Q R S T U V W X Y Z [ \ ] ^ _
6 ` a b c d e f g h i j k l m n o
7 p q r s t u v w x y z { | } ~
8 � � � � � � � � � � � � � � � �
9 � � � � � � � � � � � � � � � �
a � � � � � � � � � � � � � � � �
b � � � � � � � � � � � � � � � �
c � � � � � � � � � � � � � � � �
d � � � � � � � � � � � � � � � �
e � � � � � � � � � � � � � � � �
f � � � � � � � � � � � � � � � �
My problem is that 4 line of symbols, that begins with symbol '2', prints without first symbol '2'. I dont understant why.
I tried debug my code, but I didnt notice anything, that may help me.

Your code invokes undefined bahaviour:
sis too short to accommodate the whole string and the terminating null character. As it does not contain null terminating character you can't print it as a string withprintf(It is UB)Computers are much better at counting characters than humans:
You do not need strings for this task. Also, you should print only characters which can be printed. Some chars have special meanings like new line, line feed, backspace, bell etc.
https://godbolt.org/z/5hzbcnPeG
Also use the correct format for size_t which is
%zuor%zx