Friday, May 29, 2009

Windows flavor in Linux, YUM

Linux is bad for naive users especially while installing new software. You always see some dependency missing and all. That's what I used to think. But no more. Linux has given a break from messy-dirty way of installing a software to a very very clean and simple way.

Yes, it's by Fedora 9(New name for good old Redhat), and it's called YUM.
Yum makes installing new RPM(Redhat Packet Manager) butter smooth and a slightly simpler than Windows.
All Yum demands is an Internet connection and lo, you are done.

Just download your desired RPM and specify it to yum like this:

$yum install my.rpm

After asking you for a 'YES', it will take care of everything.

Simple right!

Thursday, May 21, 2009

Idiotic scanf() : Scanning whitespaces in a string

In C, a few functions are real nasty and scanf() is one of them. It's specially bad for inputting strings.
What will happen if you give a string:

-> scanf("%s", string)

-> Input: "C is stupid".

Well, you will have only "C" in the "string".

Reason: It happens because scanf() considers white-spaces as delimiter. So "C" being followed by a white space is considered as the only input. Simple, isn't it?

Remedy: We have something like follows:

int main()
char arr[10];
scanf("%*[ \t\n]%s", arr);


Only way is this:

#define SIZE 128

int main() {
char arr[SIZE];
char ch;
int index = 0;

while(ch != '\n' && index < SIZE)
ch = getchar();
arr[index] = ch;
arr[index] = '\0';