Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think things start going wrong from this section:</p> <pre><code> // convert show_version_library_actual2 to char* char* lib2; lib2 = &amp;show_version_library_actual2[0]; </code></pre> <p>That does not convert anything. What it does is declare a char pointer lib2 and sets it's value to the address of the first character in the show_version_library_actual2 char array. There's nothing wrong with that but no conversion is taking place.</p> <p>The sequence:</p> <pre><code> // array counter char* library_actual[100] = { lib2 }; </code></pre> <p>does not count anything. What it does is setup an array of 100 pointers to char. You initialize it with only 1 value -- the pointer to the first character in the show_version_library_actual2 character array. The other 99 values in the array are uninitalized.</p> <p>The next loop:</p> <pre><code> char* p; while (p != '\0') { n++; p = library_actual[n]; } </code></pre> <p>probably isn't what you intended since it is dealing with a mostly uninitialized array. It returns 1 but only because library_actual[0] (lib2 = first character of the show_version_library_actual2 array) is non null so the loop ends.</p> <p>I'm not sure exactly how you intended to identify the pieces of data. Maybe you thought that by adding commas that you'd get separate strings. If that's what you wanted you have to remember that in C/C++ nothing like that would happen by itself. Assignments are usually just that -- no conversion is going to happen as might happen in many other languages.</p> <p>If you need to get separate strings you'll need to do that. If you simply want to count the number of times a comma occurs that's fairly easy. For example you could do:</p> <pre><code>char *p = lib2; int n = 0; while(*p != '\0') { if(*p == ',') ++n; } </code></pre> <p>With this n will represent the number of comma. In your sample that would give you 2. I'll leave it as an exercise to you to handle the case where there's 2 items but separated by 1 comma. Hint: sometimes it's useful to add an initial or terminal separator to make processing consistent.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload