Re: Correct/example use of byleng/ldchar?
Posted in 1993
>From: uunet!hqrim.sedd.trw.com!ries (Marc Ries) >Subject: Correct/example use of byleng/ldchar? >Date: Thu, 1 Apr 1993 19:07:46 GMT >X-Informix-List-Id: <news.2952> >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> Are we looking at the code extracted from your source, or are we looking at your typing of an approximation to the code for the purposes of email? The problem in the code as supplied is that your pf_getval is not putting any data into your variable data, so of course byleng is giving odd results. Your code is copying data from the screen field with tag "field" into a variable fieldname. If this lot compiles, then you have defined a variable called fieldname somewhere. I suspect that your call to pf_getval should be: if ((errcode = pf_getval(field, data, CCHARTYPE, sizeof(data))) != 0) errorhandling(errcode); Note that I am checking whether pf_getval succeeds -- you don't, so you can't tell whether it is safe to operate on the data. If pf_getval returns a non-zero value, then you cannot process data safely. Any function which returns an error (which means any of the pf_ routines) should be error checked. If this code is not extracted directly from your source and the diagnosis of the problem is not correct, please supply the relevant extract from the actual source. Yours, Jonathan Leffler (johnl@obelix.informix.com) #include <disclaimer.h>