Unifix knowledge database - The original one

Dashboard - News - Search - List - About - Admin


Using indent on C code

Author:black - Thu Aug 21 22:36:59 2003

this slamcoded program works fine, but looks like shit:

#include <unistd.h>

int main (int argc, char **argv)
{
  if (argc < 2) { printf ("Hva har du kog i fister?\n"); }
  else if (!strcmp (argv[1], "-GiB"))
           { printf ("Gibibyte\n");  system ("df -h");
} else if (!strcmp (argv[1], "-GB"))
       { printf ("Gigabyte\n");
         system ("df -H");
} else {
 printf ("%s [-GiB|-GB]\n", argv[0]);
}
}

if you use the program indent on it, it will look real nice:

GNU style:

indent <file>

#include <unistd.h>

int
main (int argc, char **argv)
{
  if (argc < 2)
    {
      printf ("Hva har du kog i fister?\n");
    }
  else if (!strcmp (argv[1], "-GiB"))
    {
      printf ("Gibibyte\n");
      system ("df -h");
    }
  else if (!strcmp (argv[1], "-GB"))
    {
      printf ("Gigabyte\n");
      system ("df -H");
    }
  else
    {
      printf ("%s [-GiB|-GB]\n", argv[0]);
    }
}

Kernighan  & Ritchie style:

indent -kr <file>

#include <unistd.h>

int main(int argc, char **argv)
{
    if (argc < 2) {
        printf("Hva har du kog i fister?\n");
    } else if (!strcmp(argv[1], "-GiB")) {
        printf("Gibibyte\n");
        system("df -h");
    } else if (!strcmp(argv[1], "-GB")) {
        printf("Gigabyte\n");
        system("df -H");
    } else {
        printf("%s [-GiB|-GB]\n", argv[0]);
    }
}

have fun slamcoding :D
Copyright(c) Unifix.org 2002-2011


Dashboard - News - Search - List - About - Admin
 
Powered by Mikjaer Consulting Solutions - Hosted by Specialhosting.dk