[Info-vax] ChatGPT solved it for me, again...
Arne Vajhøj
arne at vajhoej.dk
Fri Feb 17 08:27:17 EST 2023
On 2/17/2023 8:20 AM, Simon Clubley wrote:
> On 2023-02-17, Slo <slovuj at gmail.com> wrote:
>> Sorry Arne, I don't trust your coding skills and an ancient language :-)
>
> That ancient language is more secure than C. :-)
>
>> Me: Convert this code to C
>> ============================
>> #include <stdio.h>
>> #include <stdlib.h>
>> #include <string.h>
>> #include <time.h>
>> int get_wattage(char *sys) {
>> return (rand() % 20) * 50 + 200;
>> }
>> int main() {
>> char sys1[256], sys2[256];
>> int watt1, watt2;
>> srand(time(NULL));
>> printf("Utility to check power supply compatibility.\n");
>> printf("Enter name of system #1: ");
>> fgets(sys1, 256, stdin);
>> printf("Enter name of system #2: ");
>> fgets(sys2, 256, stdin);
>> sys1[strcspn(sys1, "\n")] = '\0';
>> sys2[strcspn(sys2, "\n")] = '\0';
>
> OUCH! OUCH! OUCH!!!!!
>
> fgets() is not guaranteed to return a newline character.
And?
Arne
More information about the Info-vax
mailing list