this post was submitted on 21 Aug 2023
1 points (60.0% liked)

Learn To Code

29 readers
1 users here now

founded 1 year ago
MODERATORS
 

let's say I have this code

` #include #include char name[50]; int main(){ fgets(name,50,stdin); name[strcspn(name, "\n")] = '\0'; printf("hi %s", name); }

`

and I decide my name is "ewroiugheqripougheqpiurghperiugheqrpiughqerpuigheqrpiugherpiugheqrpiughqerpioghqe4r", my program will throw some unexpected behavior. How would I mitigate this?

top 1 comments
sorted by: hot top controversial new old
[–] AustralianSimon 1 points 1 year ago* (last edited 1 year ago)

Could do something basic like this or validate the input using a loop and if statements to apply rules.

https://stackoverflow.com/questions/7574606/left-function-in-c-sharp#7574615