Why can't I put ']' after the format specifier when printing 27th escape sequence?

Advertisements While I was studying the C language, I was printing ASCII codes corresponding to 0 to 255. However, while printing, an error occurred that the output stopped at 27, and after many attempts, I was able to solve it by putting a space after the character output format specifier. I became curious and ran… Read More Why can't I put ']' after the format specifier when printing 27th escape sequence?

What are the benefits and drawbacks of making a function that returns a pointer to a static global variable from another object file?

Advertisements I am thinking of doing this because it suits my compartmentalization ideas, so I am trying to figure out if it is a good idea performance-wise. // obj1.c static char *data; char* return_pointer_for_data() { return data; } // obj2.c static char *buffer; void copy_data_to_buffer(char* ptr) { buffer[5] = ptr[5]; } // main.c copy_data_to_buffer(return_pointer_for_data()); I… Read More What are the benefits and drawbacks of making a function that returns a pointer to a static global variable from another object file?

C the output is wrong

Advertisements output expression is not correct code : #include <stdio.h> #include <string.h> int main() { char a[40],b[40]; printf("character input: "); fgets(a, sizeof(a), stdin); strcpy(b, a); strrev(a); printf("%s\n", a); printf("%s", b); if (b == a) printf("palindrome"); else printf("not palindrome"); } character input: seles output: seles seles not palindrome >Solution : The function fgets can append to… Read More C the output is wrong

difference between int* member[0] and int member[0] in struct

Advertisements struct A { int zero_member[0]; int other; }; struct B { int* zero_member_ptr[0]; int other; }; printf("%d %d", sizeof(struct A), sizeof(struct B)); Output: 4 8 Why the difference? In reality I’m using this with Android NDK, and I’ve tested it at Compiler Explorer without any flag. So, if this is not standard ISO C… Read More difference between int* member[0] and int member[0] in struct

When i put 'X' or 'O' in some specific places in my 10×10 tic tac toe program, 2 spaces is registered

Advertisements I made a 10×10 tic-tac-toe program and the winner is the player who has 5 marked in a row,column and diagonals. When I put ‘X’ or ‘O’ in the first column, which is 0, or the last column, which is 9, for example: 8 0, 9 0, 0 9. There will be a second… Read More When i put 'X' or 'O' in some specific places in my 10×10 tic tac toe program, 2 spaces is registered

Converting uint_32_t to network-byte-order results in shorter bit length than expected

Advertisements I’m trying to convert an uint_64_t to network-byte-order, in order to do so, I’m splitting the uint_64_t into two uint_32_t in order to use htonl, since it can only be used with uint_32_t. I’m splitting it in the following manner: uint32_t partA = (uint32_t) (x); uint32_t partB = (uint32_t) (x >> 32); when I… Read More Converting uint_32_t to network-byte-order results in shorter bit length than expected

create 2 dimension array in C, and every cell with 512 bit size

Advertisements I want to create 2d arrays, with dimension of 2 by M, and any cell in the array will have 512 bit. I was think to create something like this: #define M 1024 typedef struct { unsigned char public_key[2][M]; unsigned char private_key[2][M]; } key_pair void keygen(key *key_pair){ srand(time(NULL)) // } But as I can… Read More create 2 dimension array in C, and every cell with 512 bit size