Sunday, April 26, 2009

The Egoist.

So, was wondering how a password field could be written in a compact way. The following source code in C, is just one of the many ways to do it.
Read through, and suggest optimizations if you can think of any.

The code:

//START.

#include "stdio.h"
#include "ctype.h"
#include "conio.h"

int counter;
char str[500];
void removelast(int);
int main(void){
  char c;
  int i;
   do{
    c = getch();
    i = (int)c;
    if(i == 13)
      goto end;
    else if(i == 8 && counter > 0){
      removelast(counter);
      putchar(0x08);
      putchar(0x20);
      putchar(0x08);
    }
    if(isprint(c)){
      printf("*");
      str[++counter] = c;
    }
  } while(counter <>
 end:
  printf("\nThe entered string is ");
  for(i=1;i<=counter;i++)
    printf("%c",str[i]);
  return 0;
}
void removelast(int a){
  str[a] = NULL;
  counter--;
}
//END.

 The above source code is allowed to be copied, transmitted,stored, and used in any way the reader sees fit. I just want people to appreciate what and how a small and beautifully written code can do wonders.

Saturday, April 25, 2009

A is A.

Well, this is officially my first post now. After seemingly long unnecessary time spent in chosing what template to use and what font and all that, here I am finally scribbling my first thoughts after creating one. Any way, just want to say to all the readers out there, that from now on, I will be posting my daily doings here, just for me to remember them, and to share them with my friends. The daily postings may include some noobish C/Java code that I so passionately write to pass my time. For the time being atleast, this is what I enjoy doing!

Ok, now... next post tomorrow. Adios!
-That was John Galt speaking.