<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jan 23, 2019 at 2:28 PM Huw Davies <<a href="mailto:huw@codeweavers.com">huw@codeweavers.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Wed, Jan 23, 2019 at 04:25:33AM +0530, Isira Seneviratne wrote:<br>
> <br>
<br>
> From 5e4bd5880b74c8340a0b41fd0867c8ee70bd2817 Mon Sep 17 00:00:00 2001<br>
> From: Isira-Seneviratne <<a href="mailto:isirasen96@gmail.com" target="_blank">isirasen96@gmail.com</a>><br>
> Date: Sat, 5 Jan 2019 10:46:15 +0530<br>
> Subject: [PATCH] ping: Add Ctrl+C event handling<br>
> <br>
> Signed-off-by: Isira-Seneviratne <<a href="mailto:isirasen96@gmail.com" target="_blank">isirasen96@gmail.com</a>><br>
> ---<br>
>  programs/ping/ping_main.c | 48 +++++++++++++++++++++++++++++++++++----<br>
>  1 file changed, 44 insertions(+), 4 deletions(-)<br>
> <br>
> diff --git a/programs/ping/ping_main.c b/programs/ping/ping_main.c<br>
> index 9c4f23959e..5e7e7542bc 100644<br>
> --- a/programs/ping/ping_main.c<br>
> +++ b/programs/ping/ping_main.c<br>
> @@ -39,8 +39,35 @@<br>
<br>
> +/* Displays ping statistics when the interrupt signal is sent to the program */<br>
> +BOOL WINAPI ping_interrupted(DWORD dwCtrlType)<br>
> +{<br>
> +    switch (dwCtrlType)<br>
> +    {<br>
> +        case CTRL_C_EVENT:<br>
> +            printf("\nPing statistics for %s\n", ip);<br>
> +            printf("\tPackets: Sent = %d, Received = %d, Lost = %d (%.0f%% loss)\n",<br>
> +                i, rec, lost, (float) lost / i * 100);<br>
> +            if (rec != 0)<br>
> +            {<br>
> +                avg /= rec;<br>
> +                printf("Approximate round trip times in milli-seconds:\n");<br>
> +                printf("\tMinimum = %dms, Maximum = %dms, Average = %.0fms\n",<br>
> +                    min, max, avg);<br>
> +            }<br>
> +            exit(0);<br>
> +        default:<br>
> +            return FALSE;<br>
> +    }<br>
> +}<br>
<br>
So the printing code now appears twice in the file, here and at the<br>
bottom of main().  What you should do is to move the printing code to<br>
a separate function that can be called from both places.<br>
<br>
Huw.<br></blockquote><div><br></div><div>Okay, will do. Thank you. <br></div></div></div>