Re: Correct/example use of byleng/ldchar?
Posted in 1993
In article <1993Apr1.190746.1391@venice.sedd.trw.com> ries@hqrim.sedd.trw.com (Marc Ries) writes: > >Am I missing something simple? I have a CCHARTYPE perform field >of length 24. I want to get what's in the field, strip off the >trailing blanks, and be able to sprintf the result (along with >some other info). > >(V2.10.XX) Both byleng(from, count) and ldchar(from, count, to) seem to >not be "stripping" the trailing blanks: > > <field = "xyz"> > char data[24]; > int len; > pf_getval("field", fieldname, CCHARTYPE, 24); > len = byleng(data, 24); > <len returns value of 24 -- I was expecting 3> > How about: while (len > 0 && data[len] == ' ') len--; I'm inferring that data contains a non-null-terminated string of length len. If informix returns a null-terminated string, you'd better make data be "char data[25]". (I don't recognize pf_getval... Is that a 4gl thing?) Of course, if you want to sprintf the result, you need to make it "char data[25]", and add the following line after the while: data[len] = '\\0'; I'm not saying that there isn't some kind of library function to do all of this, but why bother? -- Bill Foote bill@pds.com PDS Corp, Los Angeles, CA USA uunet!promdist!bill