ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Filling in character fields in a C++ program

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Filling in character fields in a C++ program

    Hi everyone.
    I am working with tables from the C ++ programming language. Whenever I want to write a record to a table that contains character fields consisting of several characters (in fact, strings), I come across the following routine. As you know, if a character field in the database consists, for example, of 10 characters, and the string "IBM" must be stored there, then the unoccupied 7 characters must be filled in with blanks. To do this, in addition to copying the string into the record structure, fill in the rest of the line with spaces.
    Isn't there a way that would fill the unused part of the character field with blanks automatically when writing?

  • #2
    I'm not sure that I follow you. Can't you just use something like memset() to fill the variable with blanks so that the database field will get those blanks?

    Comment


    • #3
      Scott, this is what I'm doing right now - I use memset to fill with blanks. Just thought there was a way not to do that, and the database would do the filling itself. After all, in an RPG, you don't need to fill with blanks.
      But, probably, these are my unnecessary whims and memset is not a big price to pay in terms of performance degradation due to filling.

      Comment


      • #4
        It's not handled by database for RPG either.

        Using RPG, you don't have to fill with blanks because RPG handles that for you when you put data into the field. For RPG, a char(10) is a simple data type, not an array the way it is in C++. If you assign 'abc' to a char(10) field, RPG will actually assign 'abc' followed by 7 blanks.

        Comment

        Working...
        X