problem about null-terminated-Collection of common programming errors


  • Alexander Maier
    masm null-terminated getmodulefilename
    In my program i call the GetModuleFileName function from the Windows Api. The function tells me the path of the running *.exe. On Windows XP machines the string (szSrc) is not null-terminated according to the MSDN. invoke GetModuleFileName,NULL,szSrc,255How can i null terminate it?

  • DevEight
    c multidimensional-array null-terminated
    I’m trying to create an array of null-terminated string arrays. Everything in the array is known at compile time, except one element which is placed into it at runtime.This is how I want the array to look: [ [“command1”, “arg”, “arg”, 0], [“command2”, 0], argv, [“command3”, “arg”, 0] ]So here command1, command2 and their args are known at compile time, only argv is placed into it at runtime. The problem is that I can’t make the this work. Currently I am doing this to create an array with NUM_COM

  • Tomasz Nurkiewicz

  • John Mahoney
    c++ arrays char null-terminated
    I am a student learning C++, and I am trying to understand how null-terminated character arrays work. Suppose I define a char array like so:char* str1 = “hello world”;As expected, strlen(str1) is equal to 11, and it is null-terminated.Where does C++ put the null terminator, if all 11 elements of the above char array are filled with the characters “hello world”? Is it actually allocating an array of length 12 instead of 11, with the 12th character being ‘\0’? CPlusPlus.com seems to suggest that o

  • Greener
    c++ arrays pointers char null-terminated
    I’ve been reading C++ for dummies lately and either the title is a misnomer or they didn’t count on me. On a section about utilizing arrays of pointers with characters strings they show a function on which I’ve been completely stumped and don’t know where to turn. char* int2month(int nMonth) { //check to see if value is in rang if ((nMonth < 0) || (nMonth > 12))return “invalid”;//nMonth is valid – return the name of the month char* pszMonths[] = {“invalid”, “January”, “February”, “March”,

  • GlassGhost
    c++ c string gcc null-terminated
    Updateturns out this is just another case of “c++ is not c blues”What I wantconst char hex[16] = “0123456789ABCDEF”;the only thing that workschar hex[16] = “0123456789ABCDE”; hex[16] = “F”;are there any compiler options or something I can do to make strings not null terminated in the gcc compiler. so that I can make a(n) constant array

  • Keith Thompson
    c string null-terminated
    As I understand, the function char *strstr(const char *s1, const char *s2); searches for the null terminated string s2 in the null terminated string s1. Let’s say, I pass a null terminated string s2, but the buffer passed as s1 is not null terminated, what will happen in such a case if the string s2 is not present in s1? The function strstr will keep searching for s2 beginning from the start address of s1, till it finds some ‘\0’. But, let’s say it doesn’t find a ‘\0’ at all? Will it access some

  • WilliamKF

  • Luchian Grigore
    c++ memset null-terminated
    What is the correct and safest way to memset the whole character array with the null terminating character? I can list a few usages:… char* buffer = new char [ARRAY_LENGTH];//Option 1: memset( buffer, ‘\0’, sizeof(buffer) ); //Option 2 before edit: memset( buffer, ‘\0’, sizeof(char*) * ARRAY_LENGTH ); //Option 2 after edit: memset( buffer, ‘\0’, sizeof(char) * ARRAY_LENGTH ); //Option 3: memset( buffer, ‘\0’, ARRAY_LENGTH ); …Does any of these have significant advant

  • user1329846
    c arrays string null-terminated
    Probably I’m just too dump for googling, but I always thought char arrays get only null terminated by an literal initialization (char x[]=”asdf”;) and got a bit surprised when I saw that this seems not to be the case.int main() {char x[2];printf(“%d”, x[2]);return 0; }Output: 0Shouldn’t an array declared as size=2*char actually get the size of 2 chars? Or am I doing something wrong here? I mean it isn’t uncommon to use a char array as a simple char array and not as a string, or is it?

  • usr55410
    c c-strings null-terminated
    I am at a total loss with this one. I can’t figure out why this isn’t working. Simple character array with a NULL terminator – except that when I output it, it doesn’t terminate!int file_create(const char *path) {//trying to trap situations where the path starts with /.goutputstreamchar path_left_15[16];strncpy(path_left_15, path, 15);printf(“%d\n”, strlen(“/.goutputstream”)+1);path_left_15[strlen(“/.goutputstream”)+1] = ‘\0’; printf(“%d\n”, strlen(path_left_15));printf(“path_left_15: %s\n”, pat

Web site is in building