# Writing/Reading a Blank String

**URL:** <https://forum.hdfgroup.org/t/writing-reading-a-blank-string/1103>\
**Category:** Hdf-forum archives\
**Created:** [August 18, 2008, 9:25am UTC](https://forum.hdfgroup.org/t/writing-reading-a-blank-string/1103 "2008-08-18T09:25:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ramakrishnan.iyer](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/r/3e96dc/32.png) [@ramakrishnan.iyer](https://forum.hdfgroup.org/u/ramakrishnan.iyer)\
**Post date:** [August 18, 2008, 9:25am UTC](https://forum.hdfgroup.org/t/writing-reading-a-blank-string/1103/1 "2008-08-18T09:25:18Z")

</div>

All,

I am creating a string datatype as given below

hid\_t stringType = H5Tcopy(H5T\_C\_S1);

&nbsp;&nbsp;&nbsp;H5Tset\_size(stringType,H5T\_VARIABLE);

&nbsp;&nbsp;&nbsp;H5Tset\_strpad(stringType,H5T\_STR\_NULLTERM );

and then creating a dataset which consists of the above datatype

I want to write 2 strings into this dataset . One of them is "HELLO"  
and the other one is a blank string " " .

The write is done as given below

char\* str[1];

str[0]=new char[6];

strcpy(str[0],"HELLO");

status = H5Dwrite(dataset, type, memspace, dspace, H5P\_DEFAULT,  
&str[0]);

delete[] str[0];

str[0]=new char[2];

strcpy(str[0]," ");

status = H5Dwrite(dataset, type, memspace, dspace, H5P\_DEFAULT,  
&str[0]);

The elements are written properly into the dataset .

The problem comes while reading . I am able to read back the first entry  
in the dataset ( i.e. the string "HELLO" ) . When I try to read the  
second element of the dataset I get this assertion

Assertion failed: buf, file ..\..\src\H5Tvlen.c, line 826 .

If there is any mistake on my part in the way I am writing a blank  
string please let me know the correct way of doing this . I am using  
hdf51.6.5 .

Thanks and Regards

Ramakrishnan
