homemade c89 code

i guess i’ve started taking it upon myself to educate a young cis lady about c programming. luckily she is using a mac.

on mac, you can open up your β€˜Terminal.app’application and run:

$ echo "#!/bin/sh\

man -t $1 $2 | open -f -a System/Applications/Preview.app\

" > pages

$ chmod 755 pages

$ ./pages c89

to view a readily accessible pdf of the c89 compiler on Preview.app, and

$ ./pages 3 atof

to view a pdf for the function β€˜atof()’ in the standard c89 header β€˜stdlib.h’

( it also helps to de-β€˜man’ your command line interface a bit )


but here’s an example program i wrote as β€˜greater.c’. :


#include<stdio.h>

#include<stdlib.h>

int main(const int argc, const char **argv){

Β  const double x = (*++argv != NULL ? atof(*argv) : (double)0);

Β  const double y = (*++argv != NULL ? atof(*argv) : (double)0);

Β  printf("%lf\n",(x > y ? x : y));

Β  return 0;

}


0 Kudos

Comments

Displaying 1 of 1 comments ( View all | Add Comment )

π–‡π–šπ–Œπ–‡π–Šπ–†π–—π•Ώπ•Ύ

π–‡π–šπ–Œπ–‡π–Šπ–†π–—π•Ώπ•Ύ's profile picture

in my eyes, using β€˜int argc and char **argv’ for user input is far less fault-prone than using β€˜scanf()’.
honestly, just don’t use scanf if you can avoid having to use it, but if you have to get user input from stdin while the program is running in real-time, like if you’re writing a REPL, then maybe using fgets() over an algorithm with a string-queue would be much better


Report Comment



i honestly get really pissed at people who teach beginners to write lines of code read user input with scanf(), because they’re teaching beginners that they should use scanf when they really shouldn’t, and it will sadly stick with a lot of programmers for far too long.
don’t use scanf.
don’t teach people to use scanf

by π–‡π–šπ–Œπ–‡π–Šπ–†π–—π•Ώπ•Ύ; ; Report