[Solved] Spaces not being replaced with newlines

Welcome to C! You have allocated no memory so you error. Use malloc to allocate the memory. I have made this code that works for you: void f(char*s,char*toString) { char c,i=0,j=0; int num=0; while(c=*(s++)) { toString[num]=c; // putchar(c); if(c==’ ‘)++i; if((j<4&&i==7)||(j>=4&&i==6)) { i=0; ++j; toString[num]=’\n’; // putchar(‘\n’); } num++; } } state_t initial_user_state_to_c(char * string) … Read more

[Solved] Can someone explain this C++ code? [closed]

If i equals 0, then you can’t look words[i-1] because you can’t do words[-1] Furthermore, when you use || operator, if the first expression is true, the second expression is not checked With i == 0 || words[i – 1] != words[i] you can print your first words because i equals 0 and the expression … Read more

[Solved] C system calls, delete the file

Just call truncate or ftruncate to cut the file to zero bytes. Then write the line you want. You don’t need to close or re-open the file, you can use your existing handle. 2 solved C system calls, delete the file

[Solved] How should I be declaring “stuff” in C++? [closed]

As you’ve noticed, if you follow this path you’ll end up with some really unwieldy names. Naming is largely up to preference (for personal or new projects) or convention (for existing projects). If you want to go learn a convention, read some code that you might want to contribute to. Most importantly, though, be consistent … Read more

[Solved] Sort Points ad Clockwise C# [closed]

var lstPnts = new List<PointF>(); lstPnts.Add(new PointF(23.92f, 6)); lstPnts.Add(new PointF(23.88f, 0)); lstPnts.Add(new PointF(0, 0)); lstPnts.Add(new PointF(0, 6)); var avgPoint = new PointF(lstPnts.Average(t=>t.X),lstPnts.Average(t=>t.Y)); var ordered = lstPnts.OrderBy(t => Math.Atan2(avgPoint.Y – t.Y, avgPoint.X – t.X)).ToArray(); We found an average point. Then we calculated the angle between mid point and the other points and sorted our array with … Read more

[Solved] Is there a stricter version of .Single()? [closed]

Single() already throws an InvalidOperationException if the result contains more than one element (or if it is empty). You were probably confusing it with First(), which doesn’t throw if there is more than one element. 2 solved Is there a stricter version of .Single()? [closed]

[Solved] How to write one line and nested ‘if’ statement without ‘?:’ (is it possible?)

You already used the two important words that are key to undestand why what you intend is not possible, but you probably haven’t grasped their full meaning: Statement and expression. The if statement (like all statements) does not yield a value, while the ?: operator is an expression that does yield a value. Distinguishing between … Read more

[Solved] How detect received message in DTLS?

In nonblocking operation, you typically have a point in the program where it waits for any of the nonblocking file descriptors to report availability of data. In the example you linked, that’s the select(…) line. In practice, you either have such a central select yourself, or have the main loop run by another library to … Read more