Custom Search

Monday, December 10, 2007

Auto Hot Key software

AutoHotkey is an open source macro-making utility for Windows that can automate almost anything by sending keystrokes and mouse clicks. It can also create hotkeys for keyboard, mouse, joystick, and handheld remote controls. Similarly, it can create abbreviations that expand as you type them (AutoText). Finally, it makes it easy to create your own graphical user interfaces and custom menus.

Its a light weight program with excellent options to automate the routine work.

http://www.autohotkey.com/


Monday, November 5, 2007

Tuesday, October 30, 2007

Blog Readers......

Your friend updates his/her blog often and you want to read it as soon as possible. How do u know whether they posted anything new in to the blog or not? If it is one blog u can visit it directly and check it. But if u read 20 blogs, its a bit time consuming task.

There is a solution for this. Blog readers.... :-)

Many desktop and online tools are available which will monitor your interested blogs and notify when there is an update. i want to give a brief idea about these tools.

Online blog readers

1. Google Reader


2. Bloglines



3. Newsalloy



4. Rojo

5. feedlounge



6. gritwire

Desktop blog readers

1. rss reader



2. Feedreader



3. attensa

4. akregator Linux(KDE)



I found a related post in one blog while writing this post. here is the link.

I found an article about reading blogs in time management site. here is the link and one more here.

Monday, October 29, 2007

Hit Counters for ur website, blogs

Add a hit counter to your website or blog and findout how many people are visited your site.
This greatly helps you in finding your site reputation.

Free hit counters are available in many sites. Some of them are mentioned below
1. Hi stats (200 + counters) Good styles
2. Atflash
3. flashiness (seems bit slow)

Html Counters
1. Easy Counter
2. Free stat counter
3. Html Hit Counter

Do you want to design your own counter using PHP, then visit these links
1. Tutorial 1
2. Tutorial 2
3. Level 10 hitcounter installer

Wednesday, October 24, 2007

Image hosting sites

There are many free image hosting sites available.

Some of them are
1. Picasaweb
2. Photobucket
3. flickr
4. FreeImageHosting
and many more

I like photobucket for bulk uploading and downloading, picasa web for upload and download few images.

A browser (like ie, firefox) flock is available for uploading photos to photobucket, flickr. It has many other features like easy blogging etc. For the list of services offered by flock, click here.

Photobucket has a special feature(I am not sure, this any other image hosting site has) that, It has the feature to generate html code for the photos u selected.

Login to Photobucket.com and upload some photos.
Ur photos will appear some thing like this.



select the images u want to show in ur site, click on "generate HTML". Photobucket generates code for u.



This is very simple way of publishing ur photos in ur website.

*click the photos to enlarge.

Tuesday, October 23, 2007

Create your own website

There are numerous sites available for creating own website.

The best one i like is www.googlepages.com
Features :
No adds,
No pop-ups
Good Templates

Drawbacks :
No PHP support
No Database support
Does not allow own template
Very less site space (100 MB)

For a list of free web hosting sites click here. This site compares all free web hosting sites with features.

Creating own site with googlepages

Open www.googlepages.com
Sign in with your existing gmail id.

You will get a similar page like this.



your website name will be ur gmail id followed by googlepages.com
for example, gmail id : suman.knr
your website name is : http://suman.knr.googlepages.com
(Remember, no www)

if u want to chane the site name, click on the "Create a new site" (located top-mid of the above page)

click on the create a new page, it asks for a name for the page and opens the page for editing



u can change the look and layout (it is located right hand side, slightly top side of the page).

A tool box is located at the left hand side of the page. Use these tools to make ur page more attractive.

"edit html" is located in the bottom - right side of the page. With which u can edit the html of particular section of the page.

Click on Images, to upload and use images in the webpage. But the drawback is, there is no mechanism to maintain the images in folders or groups. If u upload many images, it will be a bit difficult to manage in future. For more information on image uploading, click here.

Write the content what ever u want, click "publish" to save the changes and make it visible to others.

A tutorial



Part 2


For some more help on google pages, click here

Now your own webpage is ready. my website address is http://suman.knr.googlepages.com, u might want to have a site like www.sumanb.com or www.sumanb.net or etc. ( I mean with out specifying the site where u created ur page).

For this, u have some redirection sites. With which u can make ur website address as www.sumanb.co.nr or www.sumanb.tk*
The registration for redirection is very simple. type www.yourdesiredsite.tk or www.yourdesiredsite.co.nr, it will show wether the site is registered or not. If the site is not registered, u can registered by filling your details.

* ".tk "site shows some adds on top of ur page. ".co.nr" site does not show any adds and has some extra features.

http://www.titanichost.com/, brinkster offers you to create a website with ASP support, http://www.myjavaserver.com/ with JSP support.

Friday, October 12, 2007

Synergy - A Keyboard and mouse sharing software

Synergy lets you easily share a single mouse and keyboard between multiple computers with different operating systems, each with its own display, without special hardware. It's intended for users with multiple computers on their desk since each system uses its own monitor(s).

Redirecting the mouse and keyboard is as simple as moving the mouse off the edge of your screen. Synergy also merges the clipboards of all the systems into one, allowing cut-and-paste between systems. Furthermore, it synchronizes screen savers so they all start and stop together and, if screen locking is enabled, only one screen requires a password to unlock them all.

It works with Windows, Linux, Unix, Mac operating system. It has the ability to share mouse and keyboard on many machines though it runs on different OS.

Set up is very simple and configuring is also very simple.

WebSite

Download

Synergy use :



When u move the mouse to the corner of a screen, it automatically appears in other computer (of course, u can set it which corner u want to).

* Most of the description copied from the site.

Wednesday, April 25, 2007

Google as a calculator

Google is tremendously increasing the applications. It designed a calculator in the search bar itself. When you need some calculation urgently, you need not search for calculator. All the calculations can be done with google.com



for example,

type this in google,

2 + 3 * 5

you will see a result like this

2 + (3 * 5) = 17

it supports many scientific calculations also

sin(pi/2)



result is



sin(pi / 2) = 1

half a cup in teaspoons



half (1 US cup) = 24 US teaspoons

160 pounds * 4000 feet in calories

(160 pounds force) * 4 000 feet = 207.390891 kilocalories

euro to INR conversion



1 Euro = 56.012747 Indian rupees

When you need some calculations urgently, dont waste your time to search your calculator or no need to download and install a calculator application. Go to google and type what ever the calculations you need. It is very easy.



For more information visit http://www.google.co.in/intl/en/help/features.html#calculator

Tuesday, April 24, 2007

StumbleUpon -Discover great websites

An excellent addon for firefox for internet browsing lovers StumbleUpon.

Idea is simple but extremely good.



I will try to explain in my words. First, you need to install StumbleUpon, give your email id to store ur preferences.

It gives a list of topics, select your choices. I recommend you to select very few that you are really interested.

Click on save. on the toll bar click stumble

You will get a web page from your preferred choices.



There is a drop down menu on the tool bar showing ALL.

Click ALL and select a topic for example, "Internet Tools". From now on if you press stumble, you will see a web page from that "Internet Tools".



It also provides option to include web pages to StumbleUpon. open the web page you wanted to include in stumbleupon. click i like it button on stumble tool bar. It will recognize that and add it to your interested sites. It will show that page to others which matches to the type of the topic.



Here is the link to install StumbleUpon http://www.stumbleupon.com/

Saturday, April 14, 2007

Metacafe.com

If u r much interested in watching videos from across the world and wanna save them in ur PC?

here is the useful software that will make ur complete work.



have a look at this site once. Metacafe

It automatically downloads many videos from the internet when ur internet connection is idle.

There are option to specify ur interested topics and options to control the type of videos that has to be downloaded also.

U need not worry, if u r at home u can control many videos not being downloaded.



Its really cool one i got.

Wednesday, April 11, 2007

Slideshare.com

A good website for sharing powerpoint presentations. Slideshare

While browsing the net, i got this site. I felt very interesting....



Try this once. Hope u love it. It needs flash payer installed in the browser.

Complete text of the presentation is available in the bottom of the page. It is awesome. initially, We can view the text before watching entire presentation.

http://www.slideshare.net/jignesh/ddos-attacks

Saturday, March 24, 2007

Question for the week -2

2 power 4 = 16 and the sum of the digits is 1 + 6 = 7

2 power 15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26



What is the sum of the digits of the number 2 power 1000

Wednesday, March 21, 2007

Questions for the week - 1

//correct all errors and make the program do insertion sort



// There are some logical errors. Note that, there is no compilation error.



// program compiled in gcc linux fedora core 5







int X[10],



Y[10],



NumInputs,



NumY = 0;







void GetArgs(int AC, char **AV)







{ int I;











NumInputs = AC - 1;



for (I = 0; I NumInputs; I++)



X[I] = atoi(AV[I+1]);



}







void ScootOver(int JJ)







{ int K;







for (K = NumY-1; K JJ; K++)



Y[K] = Y[K-1];







}







void Insert(int NewY)







{ int J;







if (NumY = 0) {







Y[0] = NewY;



return;



}







for (J = 0; J NumY; J++) {



if (NewY Y[J]) {











ScootOver(J);



Y[J] = NewY;



return;



}



}



}







void ProcessData()







{







for (NumY = 0; NumY NumInputs; NumY++)







Insert(X[NumY]);







}







void PrintResults()







{ int I;







for (I = 0; I NumInputs; I++)



printf("%d\n",Y[I]);



}







int main(int Argc, char ** Argv)







{







GetArgs(Argc,Argv);







ProcessData();



PrintResults();



}

Tuesday, March 20, 2007

Quine

Write a C program that executes and prints itself in the output.
(Do not use any file concepts such as reading from source file, the source will not be provided.)

The answer is
A program that produces its complete source code as its only output is called a quine. This is a technique some times used in viruses.( dont ask me to write a virus or to help in writing a virus ).

char*f="char*f=%c%s%c;main()
{printf(f,34,f,34,10);}";
main(){printf(f,34,f,34,10);}

Let us understand the above program.
Before that, have a look at this code
char t[10]="%s";
char name[10]="hello";
printf(t,name);

it prints
hello

generally printf takes parameters. treats the first string is to be printed and if there is some %s in the first string, it searches for the next parameter(ignores it, if there is no corrosponding parameter in the printf call). prints it with out any doubt.

Now, let us understand this code

The program is
char*f="char*f=%c%s%c;main(){printf(f,34,f,34,10);}";
main(){printf(f,34,f,34,10);}

initially, we r declaring a character pointer f.
we are storing the text that is present in the program into the pointer p but, with some technique to print itself twice.

char*f="char*f=%c%s%c;main(){printf(f,34,f,34,10);}";
main(){printf(f,34,f,34,10);}

we are storing char *f=%c%s%c;main(){printf(f,34,f,34,10);}
in to the character pointer f
in the main we are calling a printf.
f is passed as a first variable to printf

char*f="char*f=%c%s%c;main(){printf(f,34,f,34,10);}";
main(){printf(f,34,f,34,10);}

The printf will look like

printf("char*f=%c%s%c;main(){printf(f,34,f,34,10);}" ,34,f,34,10);
observer the double quotes text in printf, it has %c%s%c

printf("char*f= %c%s%c;main(){printf(f,34,f,34,10);}",34,f,34,10);

there i am printing 34, f, 34. (34 is ascii double quotes ("))
the entire printf will look like
printf("char*f=" char*f=%c%s%c;main(){printf(f,34,f,34,10);}"",10);

we can omit 10. it is not necessary.

if it is not clear, write the program on a paper and try the steps described above.

if u r comfortable, have a look at ............(not compulsary, leave this complex example if u dont understand)
A complex quine example

/* A simple quine (self-printing program), in standard C. */

/* Note: in designing this quine, we have tried to make the code clear and readable, not concise and obscure as many quines are, so that the general principle can be made clear at the expense of length. In a nutshell: use the same data structure (called "progdata" below) to output the program code (which it represents) and its own textual representation. */

#include

void quote(const char *s)
/* This function takes a character string s and prints the
* textual representation of s as it might appear formatted in C
* code. */
{
int i;

printf(" \"");
for (i = 0; s[i]; i++) {
/* Certain characters are quoted. */
if (s[i] == '\\')
printf("\\\\");
else if (s[i] == '"')
printf("\\\"");
else if (s[i] == '\n')
printf("\\n");
/* Others are just printed as such. */
else
printf("%c", s[i]);
/* Also insert occasional line breaks. */
if (i % 48 == 47)
printf("\"\n \"");
}
printf("\"");
}

/* What follows is a string representation of the program code, from
* beginning to end (formated as per quote() function, above), except
* that the string _itself_ is coded as two consecutive '@'
* characters. */
const char progdata[] =
"/* A simple quine (self-printing program), in st"
"andard C. */\n\n/* Note: in designing this quine, "
"we have tried to make the code clear\n * and read"
"able, not concise and obscure as many quines are"
", so that\n * the general principle can be made c"
"lear at the expense of length.\n * In a nutshell:"
" use the same data structure (called \"progdata\"\n"
" * below) to output the program code (which it r"
"epresents) and its own\n * textual representation"
". */\n\n#include \n\nvoid quote(const char "
"*s)\n /* This function takes a character stri"
"ng s and prints the\n * textual representati"
"on of s as it might appear formatted in C\n "
"* code. */\n{\n int i;\n\n printf(\" \\\"\");\n "
" for (i = 0; s[i]; i++) {\n /* Certain c"
"haracters are quoted. */\n if (s[i] == '\\\\"
"')\n printf(\"\\\\\\\\\");\n else if ("
"s[i] == '\"')\n printf(\"\\\\\\\"\");\n "
" else if (s[i] == '\\n')\n printf(\"\\\\n\""
");\n /* Others are just printed as such. *"
"/\n else\n printf(\"%c\", s[i]);\n "
" /* Also insert occasional line breaks. */"
"\n if (i % 48 == 47)\n printf(\"\\"
"\"\\n \\\"\");\n }\n printf(\"\\\"\");\n}\n\n/* What "
"follows is a string representation of the progra"
"m code, from\n * beginning to end (formated as pe"
"r quote() function, above), except\n * that the s"
"tring _itself_ is coded as two consecutive '@'\n "
"* characters. */\nconst char progdata[] =\n@@;\n\nin"
"t main(void)\n /* The program itself... */\n{\n"
" int i;\n\n /* Print the program code, chara"
"cter by character. */\n for (i = 0; progdata[i"
"]; i++) {\n if (progdata[i] == '@' && prog"
"data[i + 1] == '@')\n /* We encounter "
"two '@' signs, so we must print the quoted\n "
" * form of the program code. */\n {"
"\n quote(progdata); /* Quote all. *"
"/\n i++; /* Skip second"
" '@'. */\n } else\n printf(\"%c\","
" progdata[i]); /* Print character. */\n }\n "
" return 0;\n}\n";

int main(void)
/* The program itself... */
{
int i;

/* Print the program code, character by character. */
for (i = 0; progdata[i]; i++) {
if (progdata[i] == '@' && progdata[i + 1] == '@')
/* We encounter two '@' signs, so we must print the quoted
* form of the program code. */
{
quote(progdata); /* Quote all. */
i++; /* Skip second '@'. */
} else
printf("%c", progdata[i]); /* Print character. */
}
return 0;
}


I hope the things are clear about quine. if any one can explain in better way, mail me i will forward it to all.
Thank you.

Thursday, March 15, 2007

C - Review II

1. struct fprintf{

int i;
};
void main(){
int fprintf;
struct fprintf cprintf;
cprintf.i=55;
printf("%d",cprintf.i);
}
Output : 55

2. main(){

int a = 88;
printf("%d",a<<3);
printf("%d",a<<1);
printf("%d",a<<1);
}
what is the value of a after the execution of 3 printf statements

Answer : 88. We are not modifying a value

C - Review II 3

3. Explain which one is better and why? or are they same? There is no compilation or runtime error

i) int a[1000][1000];
for(int i =0;i < 1000;i++)
for(int j=0;j < 1000;j++)
printf(“%d”,a[i][j]);

ii) int a[1000][1000];
for(int j = 0;j < 1000;j++)
for(int i = 0;i < 1000;i++)
printf(“%d”,a[i][j]);

Answer : Code snippet (i) recommonded when programming language uses row-major order

Code snippet (ii) recommonded when programming language uses column-major order

C - Review II 4 ,5

4. main() {

int reset(int );
int i=5;
reset(i);
}
int reset(int n){
if(n==0)
return 0;
else
printf(“%d”, n);
reset(n--);
}
Output: infinite recursion. It continuously prints 5 and after some time stack overflow occurs.

5.

main(){

register int i;

int *ptr;

ptr = &i;

i=10;

printf(“%d”,*ptr);

}

Output: Compilation error. We cannot refer the address of a register variable

C - Review II 6,7

6. What's the "condition" so that the following code snippet prints both HelloWorld !

if "condition"
printf ("Hello");
else
printf("World");

Answer: “condition” can replaced by !printf(“Hello”);
or printf(“Hello”)&&0
or printf(“Hello”), 0
Any expression with commas will take the final value as the expression value.

7. main(){

int i=5;

printf(“%d”,i++ * i++);

i = 5;

printf(“%d”,++i * i++);

i = 5;

printf(“%d”,i++ * ++i);

i=5;

printf(“%d”,++i * ++i);

}

Ouput: 25 36 36 49

When a variable is modified more than once in an expression it takes same value(infact final value) for all the uses or that variable.

C - Review II 8 - 11

8. main(){

int i;

i=1,2,3,4;

printf(“%d”,i);

}

output: 1
i=1 is one expression. After that 2, 3, 4 are taken as three statemets. C will ignore those three.

9. Is this code correct? If not, suggest possible modifications.

main(){

int i,j;

i=10; j=20;

i > j ? i : j = 0;

printf(“i=%d, j=%d”,i,j);

}

Output: Lvalue required

Modify the expression as *(i > j ? i : j) = 0;

The larger one will be assigned to zero.
10. main(){

int a[10],i;

for(i=0;i<10;i++)

scanf(“%d”&a[i]);

for(i=0;i<10;i++)

printf(“%d”,i[a]);

}

input : 1 2 3 4 5 6 7 8 9 1

output : 1 2 3 4 5 6 7 8 9 1

a[i] and i[a] are similar


11. main(){

char *p;

gets(p);

puts(p);

}

Output: segmentation fault.

We are using the pointer without allocating memory

C - Review II 12 - 14

12. main(){

char *p = “hello world”;

p[0]='H';

printf(“%s”,p);

}

Output: segmentation fault

hello world is treated as constant string. If we want to modify the string allocate it as

char p[20]=”hello world”;

13. struct list {

char *item;
struct list *next;
}
/* Here is the main program. */
main(int argc, char **argv)
{ ... }
This program compiled correctly but giving runtime error “Core dumped”. Why?
Because main assumes that it is returning a structure. Observe there is no semi-colon after the structure declaration. (The connection is hard to see because of the intervening comment.) Since structure-valued functions are usually implemented by adding a hidden return pointer , the generated code for main() tries to accept three arguments, although only two are passed (in this case, by the C start-up code)

14. struct record {

char *name;
int refcount : 4;
unsigned dirty : 1;
};
What is special in this structure?
The colon represents number of bits to be allocated for the varaible. In this case refcount will be allocated only 4 bits instead of 32 bits(4 bytes). It is very useful, when we want to save memory.

C - Review II 15,16

15. main(){

char *p;

p="Hello";

printf("%c\n",*&*p);

}
Output: H


16. main(){

int i=1;

while (i<=5) { printf("%d",i); if (i>2)

goto here;

i++;

}

}

fun(){

here:

printf("PP");

}
Output: at line 7 error: label ‘here’ used but not defined

C - Review II 17-20

17. main(){

int i=0;

for(;i++;printf("%d",i)) ;

printf("%d",i);

}
Output : 1

18. main(){

char *cptr,c;

void *vptr,v;

c=10; v=0;

cptr=&c; vptr=&v;

printf("%c%v",c,v);

}
Output : Error: size of v is unknown


19. main(){

int a= 0;int b = 20;char x =1;char y =10;

if(a,b,x,y)

printf("hello");

}
Output: hello


20. main(){

int i=0;

while(+(+i--)!=0)

i-=i++;

printf("%d",i);

}
Output : -1

C - Review II 21,22

21. void ( * abc( int, void ( *def) () ) ) ();
Explain the above statement in general english.
Abc is a poniter to a function, such that the function returns void and accepts one integer argument and one pointer to function which returns void.


22. main(){

int i=10,j=20;

j = i-1, j?(i,j)?i:j:j;

printf("%d %d",i,j);

}
Output 10 10

Explanation:

The Ternary operator ( ? : ) is equivalent for if-then-else statement. So the question can be written as:

if(i,j)

{

if(i,j)

j = i;

else

j = j;

}

else

j = j;

C - Review II 23,24

23. main(){

int i=4,j=7;

j = j || i++ &&amp; printf("YOU CAN");

printf("%d %d", i, j);

}
Output : 4 1
Because of short-circuit evaluation


24. main(){

static int i;

while(i<=10) (i>2)?i++:i--;

printf(“%d”, i);

}
Output: 32767
because static int will be initialized to 0.

C - Review II 25

25.main(){

int i, n;

char *x = “girl”;

n = strlen(x);

*x = x[n];

for(i=0; i < n; ++i)

{

printf(“%s\n”,x);

x++;

}

}

Output: segmentation fault

C - Review II 26,27

26. #define f(g,g2) g##g2

main(){

int var12=100;

printf("%d",f(var,12));

}

Output: 100 ## combines two arguments. F(var,12) becomes var12.


27. main()

{

int i=1;

printf(“%d”,i+++++i);

}

Output: l value required

C - Review II 28

28. Write a program to reverse the words in a string

Example: input: Hello how are you

output: you are how Hello


Solution:

void main()
{
unsigned char old_name[]={"My name is amit agrwal"},new_name[100];
int i,i_old,j,k=0;
i_old=strlen(old_name)-1;
for(i=i_old;i>=0;i--)
{
if(old_name[i]==' ' || i==0)
{
j=i;
if(i!=0)
j++;
for(;j<=i_old;j++)
new_name[k++]=old_name[j];
new_name[k++]=' ';
i_old=i-1;
}
}
new_name[k]=NULL;
printf("%s",new_name);


the solution to this problem of reversing the string is :

/*reverse a string - word by word */

#include"stdio.h"
int main()
{

char a[100]="My name is Amit Agarwal",ch,temp[100];
int i,length,j,k,l;
printf("Enetr the string\n");
for(i=0;a[i]!='\0';i++);
length=i;k=0;

for(i=length-1,j=length-1;a[i]!='\0';i--)
{
if(a[i]==' ')
{
for(l=i+1;l<=j;l++,k++)
temp[k]=a[l];
j=i-1;
temp[k]=' ';k++;
}
}

if(a[i]=='\0')
{
for(l=i+1;l<=j;l++,k++)
temp[k]=a[l];

}
temp[k]='\0';
printf("%s",temp);
return 0;
}

In the above 2 solutions u r using temporary array. I told that time and space complexity must be O(n).


my answer is without using any temporary storage is
#include"stdio.h"
#include"string.h"
void rev(char *s, int st, int e)
{
int i;
char ch;
for(i=0;i<=(e-st)/2;i++)
{
ch= s[st+i];
s[st+i]=s[e-i];
s[e-i]=ch;

}

}
void main()
{
int i, j, len;
char s[80], ch;
clrscr();

gets(s);

rev(s,0,strlen(s)-1);

printf("%s",s);
j=0;
for(i=0;i< strlen(s);i++)
{
if(s[i]==' ')
{
rev(s,j,i-1);
j=i+1;
}
}
rev(s,j,strlen(s)-1);
printf("\n\n%s",s);

getch();
}

C - Review II 29,30,31

29. I have a lower triangular matrix, all the values above the diagonal are zeros. I want to store my array in an efficient format, such that i will not store upper triangular part of the matrix.

Give me a piece of code to store and retrieve the values from new array.

Note : simulate this matrix in one dimensional array. Find formulas for storing and retrieving.


Answer:

Matrix will be in this fashion

x 0 0 0 .....0

x x 0 0 .....0

x x x 0 ......0

x x x x x ...x


where x can be any value

I will store in single dimensional array as follows (Row Major order)

(0,0) (1,0) (1,1) (2,0) (2,1) (2,2) (3,0).......

Retrieval formula for this is

a[i][j] will be stored at i * (i-1)/2 +j


Column major order is

a[i][j] will be stored at j * (j-1)/2 +i


30. Given a string s1 and a string s2, write a snippet to say whether s2 is a rotation of s1 with a single call to function strrot.

Given s1 = ABCD and s2 = CDAB, return true,
Given s1 = ABCD, and s2 = ACBD , return false.


Solution O(n^2)

#include"stdio.h"

#include"string.h"

main()

{

char a[100],b[100],temp;

int i,j,n;

gets(a);

gets(b);

n=strlen(a)-1;

for(i=0;i<=n;i++)

{

if(!strcmp(a,b)) //strcmp returns 0 if they are same

{

printf("true");

return 0;

}

temp=b[0];

for(j=1;j<=n;j++)

b[j-1]=b[j];

b[n]=temp;

}

printf("false");


}


Another solution is O(n)


#include"stdio.h"

#include "string.h"

main()

{

char a[100],b[100];

gets(a);

gets(b);

strcat(a,a);

if(strstr(a,b)==NULL) // strstr checks whether string b is substring of a or not

printf("false");

else

printf("true");


}

Q. Four people need to cross a rickety rope bridge to get back to their camp at night. Unfortunately, they only have one flashlight and it only has enough light left for seventeen minutes. The bridge is too dangerous to cross without a flashlight, and it’s only strong enough to support two people at any given time. Each of the campers walks at a different speed. One can cross the bridge in 1 minute, another in 2 minutes, the third in 5 minutes, and the slow poke takes 10 minutes to cross. How do the campers make it across in 17 minutes?

Solution:

marking 1 minute man as A

2 minute man as B

5 minute man as C

10 minutes man as D


ABCD __________________ NONE total time taken :0

CD ____________________AB total time taken : 2

CDA ____________________B total time taken 2+1 = 3

A ____________________CDB total time taken 3+10 = 13

AB ____________________CD total time taken 13+2 = 15

____________________ABCD total time taken 15+2 = 17

Saturday, March 10, 2007

C Review - I

1. main()
{
int i=3;
switch(i)
{
default:printf("zero");
case 1: printf("one");
break;
case 2:printf("two");
break;
case 3: printf("three");
break;
}
}
Answer :
three
Explanation :
The default case can be placed anywhere inside the loop. It is executed only when all
other cases doesn't match.

2. main()
{
int c=2;
printf("c=%d",c);
}
Answer:
c=2;
Explanation:
Here unary minus (or negation) operator is used twice. Same maths rules applies, ie.
minus * minus= plus.

3. main()
{
printf("\nab");
printf("\bsi");
printf("\rha");
}
Answer:
hai
Explanation:
\n newline
\b backspace
\r linefeed


4. main()
{
int i=5;
printf("%d%d%d%d%d%d",i++,i--,++i,--i,i);
}
Answer:
compiler dependent
one answer is
45545
Explanation:
The arguments in a function call are pushed into the stack from left to right. The
evaluation is by popping out from the stack. and the evaluation is from right to left, hence the result.


5. #define square(x) x*x
main()
{
int i;
i = 64/square(4);
printf("%d",i);
}
Answer:
64
Explanation:
the macro call square(4) will substituted by 4*4 so the expression becomes i = 64/4*4
. Since / and * has equal priority the expression will be evaluated as (64/4)*4 i.e. 16*4 = 64


6. #include
#define a 10
main()
{
#define a 50
printf("%d",a);
}
Answer:
50
it takes most recent value


7. #define clrscr() 100
main()
{
clrscr();
printf("%d\n",clrscr());
}
Answer:
100


8. main()
{
int i;
printf("%d",scanf("%d",&i)); // value 10 is given as input here
}
Answer:
1
Explanation:
Scanf returns number of items successfully read and not 1/0. Here 10 is given as input
which should have been scanned successfully. So number of items read is 1.


9. main()
{
main();
}
Answer:
Runtime error : Stack overflow.
Explanation:
main function calls itself again and again. Each time the function is called its return
address is stored in the call stack. Since there is no condition to terminate the function
call, the call stack overflows at runtime. So it terminates the program and results in an
error.


10. main()
{
char *str1="abcd";
char str2[]="abcd";
printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("abcd"));
}
Answer:
2 5 5
Explanation:
In first sizeof, str1 is a character pointer so it gives you the size of the pointer variable.
In second sizeof the name str2 indicates the name of the array whose size is 5 (including the '\0'
termination character). The third sizeof is similar to the second one.


11. main()
{
char not;
not=!2;
printf("%d",not);
}
Answer:
0
Explanation:
! is a logical operator. In C the value 0 is considered to be the boolean value FALSE,
and any nonzero
value is considered to be the boolean value TRUE. Here 2 is a nonzero
value so
TRUE. !TRUE is FALSE (0) so it prints 0.


12. #define FALSE 1
#define TRUE 1
#define NULL 0
main() {
if(NULL)
puts("NULL");
else if(FALSE)
puts("TRUE");
else
puts("FALSE");
}
Answer:
TRUE
Explanation:
The input program to the compiler after processing by the preprocessor is,
main(){
if(0)
puts("NULL");
else if(1)
puts("TRUE");
else
puts("FALSE");
}
Preprocessor doesn't replace the values given inside the double quotes. The check by if
condition is boolean value false so it goes to else. In second if 1
is boolean value true hence "TRUE"
is printed.

14.
int i=10;
main()
{
extern int i;
{
int i=20;
{
const volatile unsigned i=30;
printf("%d",i);
}
printf("%d",i);
}
printf("%d",i);
}
Answer:
30,20,10


15. main()
{
int i=-1;
-i;
printf("i = %d, -i= %d \n",i,-i);
}
output: i=-1, i=1


16.
main()
{
const int i=4;
float j;
j = ++i;
printf("%d %f", i,++j);
}
Answer:
Compiler error
Explanation:
i is a constant. you cannot change the value of constant


17. main()
{
int i=_l_abc(10);
printf("%d\n",--i);
}
int _l_abc(int i)
{
return(i++);
}
Answer:
9
Explanation:
return(i++) it will first return i and then increments. i.e. 10 will be returned.


18. void main()
{
int k=ret(sizeof(float));
printf("\n here value is %d",++k);
}
int ret(int ret)
{
ret += 2.5;
return(ret);
}
answer : 7


19. void main()
{
unsigned giveit=-1;
int gotit;
printf("%u ",++giveit);
printf("%u \n",gotit=--giveit);
}
Answer:
0 65535


20. void main()
{
printf(“%d”,printf(“%s”,”hello”));
}
ans : hello5


21. void main()
{
int i;
char a[]="\0";
if(printf("%s\n",a))
printf("Ok here \n");
else
printf("Forget it\n");
}
Answer:
Ok here
Explanation:
Printf will return how many characters does it print. Hence printing a null character
returns 1 which makes the if statement true, thus "Ok here" is printed.


22. main()
{
unsigned int i=10;
while(i>=0)
printf("%u ",i);
}
answer : infinte loop, observe unsigned int


23.
main()
{
int x,y=2,z,a;
if(x=y%2) z=2;
a=2;
printf("%d %d ",z,x);
}
Answer:
Garbagevalue 0


24. main()
{
int i=5;
printf("%d",++i++);
}
Answer:
Compiler error: Lvalue required in function main
Explanation:
++i yields an rvalue. For postfix ++ to operate an lvalue is required.


25. main()
{
int i=5;
printf(“%d”,i=++i ==6);
}
Answer:
1
Explanation:
The expression can be treated as i = (++i==6), because == is of higher precedence
than = operator. In the inner expression, ++i is equal to 6 yielding true(1). Hence the
result.


26. void main()
{
int i=10, j=2;
int *ip= &i, *jp = &amp;amp;j;
int k = *ip/*jp;
printf(“%d”,k);
}
ans: unexpected end of line in the file at line 5


27. main()
{
float me = 1.1;
double you = 1.1;
if(me==you)
printf("I love U");
else
printf("I hate U");
}
Answer:
I hate U



Specify all the ways that u know.
1. write a program to swap 2 numbers without using additional operator.
i) +,
limitations : overflow and underflow
ii)*, /
limitations : overflow and underflow
if one number is zero it wont work.
iii)xor ^
perfect.

3. write a program to find a number is power of 2 or not
i) taking a/2 and doing till we get 1 or not divisible
ii) using logs
iii)n&n1==0

if u have any doubts or u neeed any clarifications send me a mail to suman.knr@gmail.com

Monday, March 5, 2007

Never run yum remove yum

The most dangerous command for yum lovers is >yum remove yum Never run the above command. It will remove itself and remove all the dependencies with the open office and many applications in linux. One of my friend used this command. And unfortunately it removed yum. When we tried to install yum again, it was showing many dependencies that has to be resolved manually. it was really hard to resolve all the dependencies. So, my advise is never run the remove yum command to yum. It will successfully removes itself.

Yum, it sucks man

I have started using YUM recently.
I downloaded so many packages without worrying about the dependencies. I am using FC5. The older YUM is having small problems. One of them is, if the connection drops while downloading one file, then in the other mirror it starts from the begining.
U can update YUM, in new YUM this problem is rectified.

>yum update yum

YUM was working fine till last night, i downloaded couple of packages and installed with yum successfully. But today it started showing an error
This is the command i executed and i saw the following info

[root@localhost yum.repos.d]# yum install unrar
Loading "installonlyn" plugin
Setting up Install Process
Setting up repositories
livna [1/5]
Cannot find a valid baseurl for repo: livna
Error: Cannot find a valid baseurl for repo: livna

I searched in some forums, but I did not find exact solution to this problem. So, i saw in my friend's system. I observed that there is no livna files in the folder /etc/yum.repos.d
So, i moved livna files into desktop

These are the files i moved from /etc/yum.repos.d to my desktop
livna-devel.repo livna.repo livna.repo~ livna-testing.repo

Then i gave
>yum install unrar
its working fine....

wow, i can enjoy with yum again