Sujet : Re: Suggested method for returning a string from a C program?
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 19. Mar 2025, 22:56:01
Autres entêtes
Organisation : None to speak of
Message-ID : <87o6xwu1la.fsf@nosuchdomain.example.com>
References : 1 2 3 4
User-Agent : Gnus/5.13 (Gnus v5.13)
DFS <
nospam@dfs.com> writes:
On 3/19/2025 4:53 AM, Keith Thompson wrote:
Ike Naar <ike@sdf.org> writes:
On 2025-03-19, DFS <nospam@dfs.com> wrote:
>
I'm doing these algorithm problems at
https://cses.fi/problemset/list/
>
>
I've been playing with some of these myself.
>
Are you just looking for ones you find interesting?
>
I'm starting at the top and going down 1 by 1, no matter how simple.
I started at the top. I'm not sure how long I'll continue.
I'm actually using
scanf() for integer input, something I wouldn't do in normal code
(because the behavior is undefined if the scanned value is out
of range). This is a rare case where it's safe to assume that
stdin has nothing harmful.
>
>
>
My very 1st submission for 'Missing Number' was accepted, but each use
of scanf() generated a warning:
>
warning: ignoring return value of 'scanf' declared with attribute
'warn_unused_result' [-Wunused-result]
30 | scanf("%d", &nums[i]);
I got the same warning. scanf() returns the number of items that were
successfully scanned, and you should **always** check that result in
real world code. This autotester, which strictly constrains the input
your program will receive, is an exception, but the warning is a good
one. And of course if you want to make your submitted program more
robust, that's a good exercise, though the site won't give you extra
points for that.
spoiler: code below
[...]
//identify the missing number in a set of consecutive integers
[code snipped]
I used a different approach. I'll encode the description of the
solution using rot13.
The program is given an integer n and a list of n-1 integers, not
necessarily ordered.
The task is to determine which number is missing from the list.
Gurer'f n jryy xabja sbezhyn sbe gur fhz bs nyy a ahzoref sebz bar
gb a. Pbzchgr gur rkcrpgrq fhz, gura fhogenpg gur fhz bs gur ahzoref
tvira ba gur frpbaq vachg yvar. Gur qvssrerapr vf gur zvffvat ahzore.
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */