▲ 99 ▼ Why make it complicated? (lemmy.ml) submitted 1 year ago by HiddenLayer555@lemmy.ml to c/programmerhumor@lemmy.ml 51 comments fedilink hide all child comments Made with KolourPaint and screenshots from Kate (with the GitHub theme).
[–] racketlauncher831@lemmy.ml 3 points 1 year ago (2 children) char c; scanf("%c", &c); permalink fedilink source parent hideshow 2 child comments replies: [–] ThirdConsul@lemmy.ml 2 points 1 year ago (1 child) Great example. Wouldn't getchar() be more appropriate here? Last time I used C it was 16 years ago. permalink fedilink source parent hideshow 1 child comment replies: [–] racketlauncher831@lemmy.ml 3 points 1 year ago Yes, and no, sir, you missed the point. The procedure here is to allocate then give away, not reading a fixed-length returned value. Say you can only afford to have ten bytes in the stack. You allocate char s[10]; then give it to a library to parse something. Also telling it to abort if it's going to be longer than ten bytes, of course. permalink fedilink source parent
[–] ThirdConsul@lemmy.ml 2 points 1 year ago (1 child) Great example. Wouldn't getchar() be more appropriate here? Last time I used C it was 16 years ago. permalink fedilink source parent hideshow 1 child comment replies: [–] racketlauncher831@lemmy.ml 3 points 1 year ago Yes, and no, sir, you missed the point. The procedure here is to allocate then give away, not reading a fixed-length returned value. Say you can only afford to have ten bytes in the stack. You allocate char s[10]; then give it to a library to parse something. Also telling it to abort if it's going to be longer than ten bytes, of course. permalink fedilink source parent
[–] racketlauncher831@lemmy.ml 3 points 1 year ago Yes, and no, sir, you missed the point. The procedure here is to allocate then give away, not reading a fixed-length returned value. Say you can only afford to have ten bytes in the stack. You allocate char s[10]; then give it to a library to parse something. Also telling it to abort if it's going to be longer than ten bytes, of course. permalink fedilink source parent