http://tech-tweak.com/2010/01/get-sms-alerts-before-your-friends-birthday.html
I was forgetting my friends/relatives Birthday! And thought what could be the smarter way to remember these important dates. Either storing them in Mobile’s calendar or remembering them in mind. Thinking to store in mind – can’t store too many dates. Storing in mobile – Technology is changing, mobile set also change after days!But fortunately, there is a FREE of cost service from Google which will send you SMS alert before your friend’s Birthday. I have been using this for more than a year or two and till now, have not forget to wish their Birthdays. Some even asked, how do you know my Birthday and not forget to wish? The service here I am talking is about integrating Facebook and Orkut Birthday calendar with Google calendar which will finally send you SMS alerts.
For this we will have to configure Google Calendar account and then add Facebook and(or) Orkut B’day Calendars to it. Here we start…
Open Google Calendar from here: http://www.google.com/calendar/ login and fill your name, location, select Time Zone, press continue.
Adding mobile & SMS alerts to Google calendar:
> Click on Settings located at top right corner and select Mobile Setup. Select Country, fill-in phone number without any zero or international code and click on Send Verification Code. After few seconds you will receive SMS with verification code on your mobile, type in that code and click Finish setup. > Now its the time to setup Notifications, i.e. how you want to get alerts? by SMS or by email. Here I am talking about SMS so select SMS then type the desired time before which you want to get the alert, I have selected 10 minutes before each event. And the best thing is that you can add as many SMS reminders as you can by selecting “ Add a reminder “. Select the check-box of SMS alert. Click on Save.
—————————————————————————————————–
Adding Facebook friend’s Birthday:
Well for adding this Fb calendar to Google Calendar, login to your facebook account and add this “ Birthday Exporter “ app to your account from here http://apps.facebook.com/ical_exporter/ in order to import your friend’s birth date. Press Allow to add this app.
Click on Download your iCal file, and save this iCal file at known location on computer.After this open Google Calendar again and click on Create as show in figure below:A new page will open, fill in the details of calendar:And click on Create Calendar button.
Now click on drop-down menu of new created calendar and select Calendar Setting:In new page select Notifications and add a reminder as SMS alerts, (While adding reminder select SMS and 10 minutes as time) mark Check-box of SMS alerts, finally hit Save:> Now, click on settings:> In new page select Import Calendar option.
> Then in new pop-up, first choose the previously downloaded iCal file from facebook, select Facebook Birthdays Calendar and hit Import.Hurray! You have successfully imported all Facebook Friend’s Birthday Calendar, from now onwards you will receive SMS alerts before your Friend’s Birthday.
—————————————————————————————————–
Adding Orkut friend’s Birthdays alert:
To add Orkut friend’s Birthday Calendar, login to your Orku
t account. Birthday calendar can be imported from here: http://www.google.com/calendar/render?cid=1%23orkut@group.v.calendar.google.com to import calendar now, you can simply click on above link. Fill up your name, location and select Time Zone, click on continue if required. Now you will be asked do you want to add this calendar, select “ Yes, add this calendar “.You will see Orkut Birthday Calendar here:> Now click on Month Tab to view calendar in 30 days mode. You will see birthdays of your friends in golden colour like this:
> Click on the friends Birthday date, a bubble will appear like: > Press Copy to my calendar.
> A new page will appear like this:
> According to your wish select the repetition of alerts, I have selected Yearly from drop down menu of Repeats, as birthdays always come after a year!> Finally click on Save button to save the settings, Hurry you are done!
In case of Orkut Friend’s Birthday you will need to add each birthdates to my calendar in order to receive their SMS alerts.So, how is this solution to remember Birthdays? Hey, I missed one thing that if you will change your mobile number then only repeat first step i.e. adding mobile to Google Calendar and you are done.
If you have any trouble in this set-up then just leave comment below.
Monday, February 28, 2011
Tuesday, February 15, 2011
Juniper Interview
Q1. what will be output of..
void main()
{
int *p=0;
p++;
printf("\n %d",p);
}
-----------------------------------
Q2. what will be out put of
main()
{
f();
printf("\n heelo world \n");
}
f()
{
int i=0;
int a[10];
for (i=0;i<=10;++i)
a[i] = 0;
}
answer : infinte loop as it will overwrite value of I.
if we compile it with -O2 then it will store i in register so it will work
-----------------------------------
Q3
passing a double dimension arry to function with double pointer...
ans : It won;t work, in function we need to define array of pointer to int
---------------------------------
Q4.
array 1 (ex data[10] = { 66 77 34 2 3 25 36 56 57 89 }
array 2 (ex index[10] = { 8 5 4 3 7 6 1 9 0 2 }
arr2 shows the correct index position on data in array 1. we need to put all elements in array1 in according to position defined in array2 (index)
ans :
for (i=0;i<10;i++)
{
swap according to index
void main()
{
int *p=0;
p++;
printf("\n %d",p);
}
-----------------------------------
Q2. what will be out put of
main()
{
f();
printf("\n heelo world \n");
}
f()
{
int i=0;
int a[10];
for (i=0;i<=10;++i)
a[i] = 0;
}
answer : infinte loop as it will overwrite value of I.
if we compile it with -O2 then it will store i in register so it will work
-----------------------------------
Q3
passing a double dimension arry to function with double pointer...
ans : It won;t work, in function we need to define array of pointer to int
---------------------------------
Q4.
array 1 (ex data[10] = { 66 77 34 2 3 25 36 56 57 89 }
array 2 (ex index[10] = { 8 5 4 3 7 6 1 9 0 2 }
arr2 shows the correct index position on data in array 1. we need to put all elements in array1 in according to position defined in array2 (index)
ans :
for (i=0;i<10;i++)
{
swap according to index
Thursday, February 10, 2011
Multidimensional Arrays , pointer and functions
Chapter 23:
Two-Dimensional (and Multidimensional) Arrays
23.1: Multidimensional Arrays and Functions
23.2: Dynamically Allocating Multidimensional Arrays
C does not have true multidimensional arrays. However, because of the generality of C's type system, you can have arrays of arrays, which are almost as good. (This should not surprise you; you can have arrays of anything, so why not arrays of arrays?)
We'll use two-dimensional arrays as examples in this section, although the techniques can be extended to three or more dimensions. Here is a two-dimensional array:
int a2[5][7];
Formally, a2 is an array of 5 elements, each of which is an array of 7 ints. (We usually think of it as having 5 rows and 7 columns, although this interpretation is not mandatory.)
Just as we declared a two-dimensional array using two pairs of brackets, we access its individual elements using two pairs of brackets:
int i, j;
for(i = 0; i < 5; i++)
{
for(j = 0; j < 7; j++)
a2[i][j] = 0;
}
Make sure that you remember to put each subscript in its own, correct pair of brackets. Neither
int a2[5, 7]; /* XXX WRONG */
nor
a2[i, j] = 0; /* XXX WRONG */
nor
a2[j][i] = 0; /* XXX WRONG */
would do anything remotely like what you wanted.
23.1: Multidimensional Arrays and Functions
The most straightforward way of passing a multidimensional array to a function is to declare it in exactly the same way in the function as it was declared in the caller. If we were to call
func(a2);
then we might declare
func(int a[5][7])
{
...
}
and it's clear that the array type which the caller passes is the same as the type which the function func accepts.
If we remember what we learned about simple arrays and functions, however, two questions arise. First, in our earlier function definitions, we were able to leave out the (single) array dimension, with the understanding that since the array was really defined in the caller, we didn't have to say (or know) how big it is. The situation is the same for multidimensional arrays, although it may not seem so at first. The hypothetical function func above accepts a parameter a, where a is an array of 5 things, where each of the 5 things is itself an array. By the same argument that applies in the single-dimension case, the function does not have to know how big the array a is, overall. However, it certainly does need to know what a is an array of. It is not enough to know that a is an array of "other arrays"; the function must know that a is an array of arrays of 5 ints. The upshot is that although it does not need to know how many "rows" the array has, it does need to know the number of columns. That is, if we want to leave out any dimensions, we can only leave out the first one:
func(int a[][7])
{
...
}
The second dimension is still required. (For a three- or more dimensional array, all but the first dimension are required; again, only the first dimension may be omitted.)
The second question we might ask concerns the equivalence between pointers and arrays. We know that when we pass an array to a function, what really gets passed is a pointer to the array's first element. We know that when we declare a function that seems to accept an array as a parameter, the compiler quietly compiles the function as if that parameter were a pointer, since a pointer is what it will actually receive. What about multidimensional arrays? What kind of pointer is passed down to the function?
The answer is, a pointer to the array's first element. And, since the first element of a multidimensional array is another array, what gets passed to the function is a pointer to an array. If you want to declare the function func in a way that explicitly shows the type which it receives, the declaration would be
func(int (*a)[7])
{
...
}
The declaration int (*a)[7] says that a is a pointer to an array of 7 ints. Since declarations like this are hard to write and hard to understand, and since pointers to arrays are generally confusing, I recommend that when you write functions which accept multidimensional arrays, you declare the parameters using array notation, not pointer notation.
What if you don't know what the dimensions of the array will be? What if you want to be able to call a function with arrays of different sizes and shapes? Can you say something like
func(int x, int y, int a[x][y])
{
...
}
where the array dimensions are specified by other parameters to the function? Unfortunately, in C, you cannot. (You can do so in FORTRAN, and you can do so in the extended language implemented by gcc, and you will be able to do so in the new version of the C Standard ("C9X") to be completed in 1999, but you cannot do so in standard, portable C, today.)
Finally, we might explicitly note that if we pass a multidimensional array to a function:
int a2[5][7];
func(a2);
we can not declare that function as accepting a pointer-to-pointer:
func(int **a) /* WRONG */
{
...
}
As we said above, the function ends up receiving a pointer to an array, not a pointer to a pointer.
23.2: Dynamically Allocating Multidimensional Arrays
We've seen that it's straightforward to call malloc to allocate a block of memory which can simulate an array, but with a size which we get to pick at run-time. Can we do the same sort of thing to simulate multidimensional arrays? We can, but we'll end up using pointers to pointers.
If we don't know how many columns the array will have, we'll clearly allocate memory for each row (as many columns wide as we like) by calling malloc, and each row will therefore be represented by a pointer. How will we keep track of those pointers? There are, after all, many of them, one for each row. So we want to simulate an array of pointers, but we don't know how many rows there will be, either, so we'll have to simulate that array (of pointers) with another pointer, and this will be a pointer to a pointer.
This is best illustrated with an example:
#include
int **array;
array = malloc(nrows * sizeof(int *));
if(array == NULL)
{
fprintf(stderr, "out of memory\n");
exit or return
}
for(i = 0; i < nrows; i++)
{
array[i] = malloc(ncolumns * sizeof(int));
if(array[i] == NULL)
{
fprintf(stderr, "out of memory\n");
exit or return
}
}
array is a pointer-to-pointer-to-int: at the first level, it points to a block of pointers, one for each row. That first-level pointer is the first one we allocate; it has nrows elements, with each element big enough to hold a pointer-to-int, or int *. If we successfully allocate it, we then fill in the pointers (all nrows of them) with a pointer (also obtained from malloc) to ncolumns number of ints, the storage for that row of the array. If this isn't quite making sense, a picture should make everything clear:
Once we've done this, we can (just as for the one-dimensional case) use array-like syntax to access our simulated multidimensional array. If we write
array[i][j]
we're asking for the i'th pointer pointed to by array, and then for the j'th int pointed to by that inner pointer. (This is a pretty nice result: although some completely different machinery, involving two levels of pointer dereferencing, is going on behind the scenes, the simulated, dynamically-allocated two-dimensional "array" can still be accessed just as if it were an array of arrays, i.e. with the same pair of bracketed subscripts.)
If a program uses simulated, dynamically allocated multidimensional arrays, it becomes possible to write "heterogeneous" functions which don't have to know (at compile time) how big the "arrays" are. In other words, one function can operate on "arrays" of various sizes and shapes. The function will look something like
func2(int **array, int nrows, int ncolumns)
{
}
This function does accept a pointer-to-pointer-to-int, on the assumption that we'll only be calling it with simulated, dynamically allocated multidimensional arrays. (We must not call this function on arrays like the "true" multidimensional array a2 of the previous sections). The function also accepts the dimensions of the arrays as parameters, so that it will know how many "rows" and "columns" there are, so that it can iterate over them correctly. Here is a function which zeros out a pointer-to-pointer, two-dimensional "array":
void zeroit(int **array, int nrows, int ncolumns)
{
int i, j;
for(i = 0; i < nrows; i++)
{
for(j = 0; j < ncolumns; j++)
array[i][j] = 0;
}
}
Finally, when it comes time to free one of these dynamically allocated multidimensional "arrays," we must remember to free each of the chunks of memory that we've allocated. (Just freeing the top-level pointer, array, wouldn't cut it; if we did, all the second-level pointers would be lost but not freed, and would waste memory.) Here's what the code might look like:
for(i = 0; i < nrows; i++)
free(array[i]);
free(array);
Read sequentially: prev next top
Two-Dimensional (and Multidimensional) Arrays
23.1: Multidimensional Arrays and Functions
23.2: Dynamically Allocating Multidimensional Arrays
C does not have true multidimensional arrays. However, because of the generality of C's type system, you can have arrays of arrays, which are almost as good. (This should not surprise you; you can have arrays of anything, so why not arrays of arrays?)
We'll use two-dimensional arrays as examples in this section, although the techniques can be extended to three or more dimensions. Here is a two-dimensional array:
int a2[5][7];
Formally, a2 is an array of 5 elements, each of which is an array of 7 ints. (We usually think of it as having 5 rows and 7 columns, although this interpretation is not mandatory.)
Just as we declared a two-dimensional array using two pairs of brackets, we access its individual elements using two pairs of brackets:
int i, j;
for(i = 0; i < 5; i++)
{
for(j = 0; j < 7; j++)
a2[i][j] = 0;
}
Make sure that you remember to put each subscript in its own, correct pair of brackets. Neither
int a2[5, 7]; /* XXX WRONG */
nor
a2[i, j] = 0; /* XXX WRONG */
nor
a2[j][i] = 0; /* XXX WRONG */
would do anything remotely like what you wanted.
23.1: Multidimensional Arrays and Functions
The most straightforward way of passing a multidimensional array to a function is to declare it in exactly the same way in the function as it was declared in the caller. If we were to call
func(a2);
then we might declare
func(int a[5][7])
{
...
}
and it's clear that the array type which the caller passes is the same as the type which the function func accepts.
If we remember what we learned about simple arrays and functions, however, two questions arise. First, in our earlier function definitions, we were able to leave out the (single) array dimension, with the understanding that since the array was really defined in the caller, we didn't have to say (or know) how big it is. The situation is the same for multidimensional arrays, although it may not seem so at first. The hypothetical function func above accepts a parameter a, where a is an array of 5 things, where each of the 5 things is itself an array. By the same argument that applies in the single-dimension case, the function does not have to know how big the array a is, overall. However, it certainly does need to know what a is an array of. It is not enough to know that a is an array of "other arrays"; the function must know that a is an array of arrays of 5 ints. The upshot is that although it does not need to know how many "rows" the array has, it does need to know the number of columns. That is, if we want to leave out any dimensions, we can only leave out the first one:
func(int a[][7])
{
...
}
The second dimension is still required. (For a three- or more dimensional array, all but the first dimension are required; again, only the first dimension may be omitted.)
The second question we might ask concerns the equivalence between pointers and arrays. We know that when we pass an array to a function, what really gets passed is a pointer to the array's first element. We know that when we declare a function that seems to accept an array as a parameter, the compiler quietly compiles the function as if that parameter were a pointer, since a pointer is what it will actually receive. What about multidimensional arrays? What kind of pointer is passed down to the function?
The answer is, a pointer to the array's first element. And, since the first element of a multidimensional array is another array, what gets passed to the function is a pointer to an array. If you want to declare the function func in a way that explicitly shows the type which it receives, the declaration would be
func(int (*a)[7])
{
...
}
The declaration int (*a)[7] says that a is a pointer to an array of 7 ints. Since declarations like this are hard to write and hard to understand, and since pointers to arrays are generally confusing, I recommend that when you write functions which accept multidimensional arrays, you declare the parameters using array notation, not pointer notation.
What if you don't know what the dimensions of the array will be? What if you want to be able to call a function with arrays of different sizes and shapes? Can you say something like
func(int x, int y, int a[x][y])
{
...
}
where the array dimensions are specified by other parameters to the function? Unfortunately, in C, you cannot. (You can do so in FORTRAN, and you can do so in the extended language implemented by gcc, and you will be able to do so in the new version of the C Standard ("C9X") to be completed in 1999, but you cannot do so in standard, portable C, today.)
Finally, we might explicitly note that if we pass a multidimensional array to a function:
int a2[5][7];
func(a2);
we can not declare that function as accepting a pointer-to-pointer:
func(int **a) /* WRONG */
{
...
}
As we said above, the function ends up receiving a pointer to an array, not a pointer to a pointer.
23.2: Dynamically Allocating Multidimensional Arrays
We've seen that it's straightforward to call malloc to allocate a block of memory which can simulate an array, but with a size which we get to pick at run-time. Can we do the same sort of thing to simulate multidimensional arrays? We can, but we'll end up using pointers to pointers.
If we don't know how many columns the array will have, we'll clearly allocate memory for each row (as many columns wide as we like) by calling malloc, and each row will therefore be represented by a pointer. How will we keep track of those pointers? There are, after all, many of them, one for each row. So we want to simulate an array of pointers, but we don't know how many rows there will be, either, so we'll have to simulate that array (of pointers) with another pointer, and this will be a pointer to a pointer.
This is best illustrated with an example:
#include
int **array;
array = malloc(nrows * sizeof(int *));
if(array == NULL)
{
fprintf(stderr, "out of memory\n");
exit or return
}
for(i = 0; i < nrows; i++)
{
array[i] = malloc(ncolumns * sizeof(int));
if(array[i] == NULL)
{
fprintf(stderr, "out of memory\n");
exit or return
}
}
array is a pointer-to-pointer-to-int: at the first level, it points to a block of pointers, one for each row. That first-level pointer is the first one we allocate; it has nrows elements, with each element big enough to hold a pointer-to-int, or int *. If we successfully allocate it, we then fill in the pointers (all nrows of them) with a pointer (also obtained from malloc) to ncolumns number of ints, the storage for that row of the array. If this isn't quite making sense, a picture should make everything clear:
Once we've done this, we can (just as for the one-dimensional case) use array-like syntax to access our simulated multidimensional array. If we write
array[i][j]
we're asking for the i'th pointer pointed to by array, and then for the j'th int pointed to by that inner pointer. (This is a pretty nice result: although some completely different machinery, involving two levels of pointer dereferencing, is going on behind the scenes, the simulated, dynamically-allocated two-dimensional "array" can still be accessed just as if it were an array of arrays, i.e. with the same pair of bracketed subscripts.)
If a program uses simulated, dynamically allocated multidimensional arrays, it becomes possible to write "heterogeneous" functions which don't have to know (at compile time) how big the "arrays" are. In other words, one function can operate on "arrays" of various sizes and shapes. The function will look something like
func2(int **array, int nrows, int ncolumns)
{
}
This function does accept a pointer-to-pointer-to-int, on the assumption that we'll only be calling it with simulated, dynamically allocated multidimensional arrays. (We must not call this function on arrays like the "true" multidimensional array a2 of the previous sections). The function also accepts the dimensions of the arrays as parameters, so that it will know how many "rows" and "columns" there are, so that it can iterate over them correctly. Here is a function which zeros out a pointer-to-pointer, two-dimensional "array":
void zeroit(int **array, int nrows, int ncolumns)
{
int i, j;
for(i = 0; i < nrows; i++)
{
for(j = 0; j < ncolumns; j++)
array[i][j] = 0;
}
}
Finally, when it comes time to free one of these dynamically allocated multidimensional "arrays," we must remember to free each of the chunks of memory that we've allocated. (Just freeing the top-level pointer, array, wouldn't cut it; if we did, all the second-level pointers would be lost but not freed, and would waste memory.) Here's what the code might look like:
for(i = 0; i < nrows; i++)
free(array[i]);
free(array);
Read sequentially: prev next top
Wednesday, February 2, 2011
Silly window syndrome
When there is no synchronization between the sender and receiver regarding capacity of the flow of data or the size of the packet, the window syndrome problem is created. When the silly window syndrome is created by the sender, Nagle's solution is used. Nagle's solution requires that the sender sends the first segment even if it is a small one, then the sender waits until an ACK is received or a maximum sized segment (MSS) is accumulated.
When the silly window syndrome is created by the receiver, David D Clark's solution is used. Clark's solution closes the window until another segment of maximum segment size (MSS) can be received or the buffer is half empty.
When the silly window syndrome is created by the receiver, David D Clark's solution is used. Clark's solution closes the window until another segment of maximum segment size (MSS) can be received or the buffer is half empty.
Subscribe to:
Posts (Atom)