Please help, why we get wrong element in array,

this is my code : #include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char **argv) { char db_names[3][36] = {}; strncpy(db_names[0], "6e64e40c-57f6-11ec-91ca-001a6496977d", 36); strncpy(db_names[1], "90e852c8-502d-11ec-91ca-001a6496977d", 36); strncpy(db_names[2], "28712b0e-57f6-11ec-91ca-001a6496977d", 36); printf("index 0 %s\n", db_names[0]); printf("index 0 %s\n", db_names[1]); printf("index 0 %s\n", db_names[2]); return EXIT_SUCCESS; } print element in array : index 0 : 6e64e40c-57f6-11ec-91ca-001a6496977d90e852c8-502d-11ec-91ca-001a6496977d28712b0e-57f6-11ec-91ca-001a6496977d index… Read More Please help, why we get wrong element in array,

printf() is printing a character after the terminating character in C, how do I fix this?

I have a for loop in randomString() that puts a random character into the first x indexes of a string, where x < the string length. I then add a ‘\0’ to the string and print it with printf() but it prints 1 more character than x and that character is always the same, I… Read More printf() is printing a character after the terminating character in C, how do I fix this?

When I run my code it display random symbols at the end

I am separating a string into words and when I run the source code, it works but at the end it displays random symbols and letter. #include <iostream> #include <cstring> #include <cctype> using namespace std; void seperatestring(string str); int main() { string str; cout << "Enter a string: "; getline(cin, str); seperatestring(str); return 0; }… Read More When I run my code it display random symbols at the end

This simple C code about string arrays works while it shoudn't and I don't know why

I know there are other ways to solve this like with a calloc but the question here is why does it work while it shouldn’t? #include <stdio.h> #include <stdlib.h> #include <string.h> void function (char **, char **); int main () { char *list[2], *list1[] = {"word0", "word1", "word2"}; function(list, list1); return 0; } void function… Read More This simple C code about string arrays works while it shoudn't and I don't know why