What is "short item count" in fread()? - fread

When I was 'man fread', I got this:
RETURN VALUE
fread() and fwrite() return the number of items successfully read or written (i.e., not the number of characters). If an error
occurs, or the end-
of-file is reached, the return value is a short item count (or zero).
fread() does not distinguish between end-of-file and error, and callers must use feof(3) and ferror(3) to determine which occurred.
So my question is to how to understand "short item count". Please bear with my English. Why here involves type "short"? Can you someone give an example of what does "short item count" look like? Thanks.

The meaning of "short" in fread man page does not refer to a data type.
"Short" in this case means "less then expected". If fread() expected to read 4 objects, but only read 3, it will return the value 3.
I believe that the the man page should be re-written to say:
"If an error occurs, or the end-of-file is reached, the return value is the number of items successfully read or written up until the error or EOF occurred.

If you want 4, and you have 3, then you're short 1.

Related

Substring length failed (takes more than is set to take)

I have a Microsoft Flow that has failed with the following message:
Body
{
"status": 400,
"message": "Invalid Mashup Expression using supplied values.\r\n inner exception: Microsoft SQL: String or binary data would be truncated.",
}
I know what this means, in this case, it's about a SQL column that has a nvarchar(2000) set as a limitation. I take care of this in my flow before inserting it with an "SQL insert action". I convert the HTML (from email) to a text (source is 5024 long),
after this I check (condition) if the length is greater than 1999 (it is greater so it goes into the Yes part), there I take a substring of this 5024 long string like this "substring(body('converetedHTML'),0,1999)" (note that this works for all previous runs) but for some reason, for this 1 Flow it takes 2023 instead of 1999 hence the error message.
On each step it has what it's supposed to have except on the SQL insert action, the value of this variable that has 1999 becomes 2023. No idea how this can be.
Can anyone suggest me things to look for, or help me out because according to me this is a "malfunctioning" and not a logical mistake but I could be wrong, anyway I want to figure this out?
Thank you all in advance!
#Nick , Thank you for pointing that out, this was indeed the issue, there where "\n" in the content and this was causing the +X amount over the limit that was set.
Thank you very much !

'Argument 'Start' must be greater than zero. ' exception when using Mid function

When I use Mid function
MsgBox(Mid(RXdata, RXdataLen - 3, 1))
in vb.net, I always get the following message
Additional information: Argument 'Start' must be greater than zero.
I think it is impossible since the RdataLen is 9, the 'Start' is definitely larger than 9. RXdata is the data that I read from SerialPort.
Any thought on how come it happens?
Thanks

How to increase the length of select-options in UI

As I understood, select-options in abap just takes 45 characters from UI.
Whatever I assign the type of select-option, it doesnt take more then 45 characters.
SELECT-OPTIONS: s_key FOR somlreci1-receiver NO INTERVALS VISIBLE LENGTH 100.
somlreci1-receiver is char(1215). But I cannot write more than 45 into that select-option.
Any way to increase this length ?
This official link
http://help.sap.com/abapdocu_70/en/ABAPSELECT-OPTIONS.htm
says it isn't possible to pass input larger than 45 chars, sorry :|
At the end of the documentation posted by #vlad-ardelean it mentions that:
If a selection criterion for data types is supplied with data when
calling up an executable program with SUBMIT
...
If the selection criterion is declared with the addition NO-DISPLAY,
no conversion routine or truncation will be performed for the first
row either.
You could declare the select-options as NO-DISPLAY in your main program, then call it from a second program with
SUBMIT programname WITH so_field EQ lv_longdata SIGN 'I'.
...or similar to pass the long value to the main program. It's a pretty convoluted way of doing it, however.
In addition to #vlad-ardelean's answer: It might be interesting to note that in recent releases, the maximum field length was raised to 255 characters (see http://help.sap.com/abapdocu_731/en/ABAPSELECT-OPTIONS.htm).

Test of a regex (substring) occurs anywhere in any of the items in an array of strings

My spec wants to test if a certain substring occurs withing any entry of an array of strings.
p #banner.errors.messages[:base] #=> ["Specify a leader text or an image, not both"]
All my spec really wants to know, is whether or not the "not both" string occurs in any of the array-items in there.
#banner.errors.messages[:base].should include(/not both/)
fails, because "not both" is not included in ["Specify a leader text or an image, not both"]
Note: When I test against the literal string (should include("Specify...both"), things work. But that seems dirty to me. Such user-faced texts are not critical for the test to pass; and such texts will change: every time the error message is changed, I will need to update my tests.
Maybe like this?
#banner.errors.messages[:base].join.should match(/not both/)
But note that there is a edge case where the match might be over two or more lines, e.g. a line ending with "not " and the next line is " both".

Give state diagrams of DFAs recognizing the following languages. In all parts the alphabet is {0,1 }

Im trying to get the hang of drawing DFAs. I have the following problem to do with my following attempt, was wondering if anyone could tell me if im correct, or if incorrect what im doing wrong. Thanks! Also, if anyone has a good resource to learn more about how to do these, it would be greatly appreciated.
Give state diagrams of DFAs recognizing the following languages. In all parts the alphabet is {0,1 }
{w | the length of w is at most 5}
Here are some clues.
"At most 5": this implies you must do some counting. In state machines, counting is accomplished by the context of each node. In other words, you will require a number of nodes, each with a special meaning, and that meaning will be your "counter value."
"At most 5": This means you must accept words of length 0, 1, 2, 3, 4, and 5. (All of which have unique values, hint hint.)
Your alphabet is {0,1}, but there are no requirements of the language of the frequency, ordering, or anything related to 0 and 1. This means every time there is a transition for 0, the same transition must be available to 1, and vice versa. (Or some equivalent relation that reduces to this rule - but this is in parentheses because it's not something you need to think about.)
Here are your errors:
You have no marked start state.
The strings "0", "" (the empty string), "1" are rejected, but are within the prescribed language. In other words, you are accepting only words that are exactly length 5, not all words that are length 5 and less.
Since the alphabet is {0, 1}, you must specify at EACH state what happens when either a 0 or a 1 is encountered. If you encounter an input character whose edge is NOT specified, by convention you are going to the dead state, a state that always returns to itself and is never accepted, but is left undrawn. This is why your right-most state is unnecessary, but your left states are incomplete.
Final, big hint: You can have more than one "Accept" or "Final" state.
I think the DFA shown above is wrong. It will accept strings up to length 5 so you should make all the first six states to be final states. You are accepting only '1's but it should also accept '0's......so attach 0 with all 1's.