Originally Posted by
laserlight
No, it isn't. The supplied code does not do any indenting at all.
I'm really confused: isn't it obvious that these are examples of programs that change the alphabetic case of the input? They have nothing to do with indenting of code. You cannot ident anything merely by calling toupper or tolower on each input character and then printing the result.
I mean, this is the question stated in the page you linked to:
Nothing at all about indenting.
I just indented the first and second code with the given command. Let's see code as it is on link provided:
Code:
#include <stdio.h>
#include <ctype.h>
#include <string.h>
char *getbasename(char *);
/* convert input to lower or upper case depending on argv[0]*/
int main(int argc, char *argv[])
{
int c, (*convert)(int) = NULL;
char* bn;
if (strcmp((bn = getbasename(argv[0])), "lower") == 0)
convert = tolower;
else if (strcmp(bn, "upper") == 0)
convert = toupper;
else
return 1;
while ((c = getchar()) != EOF)
putchar((*convert)(c));
return 0;
}
char *getbasename(char *s)
{
char *p;
char *base;
for (base = p = s; *p != '\0'; p++)
if (*p == '/')
base = p;
return base + 1;
}
Tabs before some statements are 8 spaces (on some sites anyway). With the first command they became 4:
Code:
#include <stdio.h>
#include <ctype.h>
#include <string.h>
char *getbasename(char *);
/* convert input to lower or upper case depending on argv[0]*/
int main(int argc, char *argv[])
{
int c, (*convert) (int) = NULL;
char *bn;
if(strcmp((bn = getbasename(argv[0])), "lower") == 0)
convert = tolower;
else if(strcmp(bn, "upper") == 0)
convert = toupper;
else
return 1;
while((c = getchar()) != EOF)
putchar((*convert) (c));
return 0;
}
char *getbasename(char *s)
{
char *p;
char *base;
for(base = p = s; *p != '\0'; p++)
if(*p == '/')
base = p;
return base + 1;
}