Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C program

Name: Anonymous 2010-07-13 18:06

Make me a C program that reads given two integers (no limits) and outputs the largest.

Do this in a proper GNU hello.c way.

Name: Anonymous 2010-07-19 19:52

>>88
You should have received a copy of the GNU General Public License along with
this program.

nice try, but you have failed.

#include <stdio.h>
#include <string.h>

#define USAGE(name) ({ printf("Usage: %s number number\n", (name)); exit(EXIT_FAILURE); })

int main(int argc, char *argv[argc])
{ char *name = (argv++)[0];
  if(argc != 3)
    USAGE(name);
  int len[2] = {0};
  int larger = 0;
  for(int i = 0; i < 2; ++i)
    for(int j = 0; argv[i][j];)
    { if(argv[i][j] < '0' || argv[i][j] > '9')
        USAGE(name);
      if(argv[i][j] == '0')
      { ++argv[i];
        --j; }
      else
      { if(i == 2 && !larger)
        { int t = argv[0][j] - argv[1][j];
          if(t) larger = (t < 0); }
        ++len[i]; }}
  int t = len[0] - len[1];
  ++argv;
  if(t)
    puts(argv[t < 0];
  else
    puts(argv[larger];
  return 0; }

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List