What would be the output of this Code ?

Hello, Guys let’s have a fun, i am giving  you a code just tell me what will be the output of this code if you enter there parameters.

For Test case 1 -->Q
For Test case 2 -->QQ

Please tell why putchar() function is not working and if it is working why it is not taking any Char input?


#include <stdio.h>
main()
{
putc(getc(stdin),stdout);
putchar(getchar( ));
return 0;
}

Explain the output for these test cases.

connecting to archive.ubuntu.com takes too long

I have a Ubuntu 13.04 that I just installed fresh. Now if I try to do anything with apt-get, it tries to connect to archive.ubuntu.com .. It stays at [Connecting to archive.ubuntu.com (2001:67c:1360:8c01::1a)] phase for like 2 minutes, after which it actually starts to communicate and download stuff …

Eventually it always connects, but in waits at the [Connecting to archive.ubuntu.com (2001:67c:1360:8c01::1a)] phase everytime for like 2 minutes !

I didn’t have this problem previously on Ubuntu 13.04, right after reinstalling the OS ..

Solution:

I figured out the problem. Posted below as an answer!

Running the following command in Terminal tells if IPv6 is enabled or not:

cat /proc/sys/net/ipv6/conf/all/disable_ipv6

0 means its enabled, while 1 means its disabled.

To disable IPv6 from within Terminal, enter the following and reboot:

echo "#disable ipv6" | sudo tee -a /etc/sysctl.conf
echo "net.ipv6.conf.all.disable_ipv6 = 1" | sudo tee -a /etc/sysctl.conf
echo "net.ipv6.conf.default.disable_ipv6 = 1" | sudo tee -a /etc/sysctl.conf
echo "net.ipv6.conf.lo.disable_ipv6 = 1" | sudo tee -a /etc/sysctl.conf

After boot, re-run the first command, and it should be 1 now, after running this run

sudo sysctl -p

all output should be 1, now ipv6 is disable here.

Can’t find a usable init.tcl in the following directories

sometimes while installing ns2  this error “application-specific initialization failed: Can’t find a usable init.tcl in the following directories: ” sucks , we don’t know what to do.

I have a solution.

application-specific initialization failed: Can’t find a usable init.tcl in the following directories:/root/ns2/ns-allinone-2.34/lib/tcl8.4 /usr/local/lib/tcl8.4 /usr/lib/tcl8.4 /usr/local/library /usr/library /usr/tcl8.4.18/library /tcl8.4.18/library /root/ns2/ns-allinone-2.34/lib/tcl8.4

or at local folder too 

There are some solution please try may be they can help:

Solution 1:
1) Go to location root-usr-local-bin by giving following command in terminal
cd /usr/local/bin
2) There you would find the ns file. We just need to remove it by giving following command
rm ns
3) Thats it, you are done. Now your ns starts running successfully.

Solution 2:

 This error can happen if you make any changes to the “ns-allinone-2.34/” directory :
Renaming the directory, moving the directory to another location,
i.e. anything that will change the “/home/arungupta2008/ns-allinone-2.34/tcl8.4.18/lib/” path.
Or when changes were made in /home/arungupta2008/ns-allinone-2.34/tcl8.4.18/lib/
Note : 
The binary ‘ns’ is hard coded to know the location of it’s libraries, tclsh8* :
/home/arungupta2008/ns-allinone-2.34/tcl8.4.18/bin/, /home/arungupta2008/ns-allinone-2.34/tcl8.4.18/lib/

Workarounds, fixes : 
1) cd ns-allinone-2.34/tcl8.4.18/ && ln -s lib/ library
2) Reinstall ns-allinone-2.34  2. The problem is because, ns executable is also at /usr which is conflicting.

 

Note : while removing symlinks first make that file removable then , you can remove that file  for Ex.     chmod 755 ns

Intel@ GM965 Driver problem while installing Bluestack

Hello guys ,i was trying to install bluestacks for my laptop compaq presario 785tu ,which one have Intel @ GM965 integrated graphics card so , it was giving me graphics error to update the graphics driver but my driver was upto date still it was giving me error .

Error_img_bluestack

to i googled it more then i tried this Intel’s Graphics  Accelerator then

downloadmirror.intel.com/18223/a08/win7_1512754.exe
bluestacks started to work !!
all the best guys

Adding Leach protocol in ns2.34

let’s your ns2 is installed in /home/arun/ns/ns-allinone2.34
I suppose that ns-2.34 is installed with the compiler gcc-4.3.
download both files in  …//ns.2.34
1. LeachCode
2.Installing_file
and make sure that in leach-setup.sh please change the path in this file and run

arun@merom:~$ cd /home/arun/ns/ns-allinone-2.34/ns-2.34/
arun@merom:/home/arun/ns/ns-allinone-2.34/ns-2.34$ sudo bash leach-setup.sh
arun@merom:/home/arun/ns/ns-allinone-2.34/ns-2.34$./configure
arun@merom:/home/arun/ns/ns-allinone-2.34/ns-2.34$make clean
arun@merom:/home/arun/ns/ns-allinone-2.34/ns-2.34$make depend
arun@merom:/home/arun/ns/ns-allinone-2.34/ns-2.34$make
arun@merom:/home/arun/ns/ns-allinone-2.34/ns-2.34$make install

after running  “make ” you will get error

[trace/cmu-trace.cc: In member function ‘void CMUTrace::format(Packet*, const char*)’:
trace/cmu-trace.cc:1327: error: ‘format_rca’ was not declared in this scope

Once the above steps are done, run the following commands in the Terminal:
./configure
make clean
make depend
make
When you using the make command you will get the following error:
Code:
********************************************************************
trace/cmu-trace.cc: In member function ‘void CMUTrace::format(Packet*, const char*)’:
trace/cmu-trace.cc:1327: error: ‘format_rca’ was not declared in this scope
trace/cmu-trace.cc: At global scope:
trace/cmu-trace.cc:1523: error: no ‘void CMUTrace::format_rca(Packet*, int)’ member function declared in class ‘CMUTrace’
make: *** [trace/cmu-trace.o] Error 1
********************************************************************
  To fix it you need to add the following code in “cmu-trace.h” file starting from line 165:
Code:
********************************************************************
 #ifdef MIT_uAMPS
 void    format_rca(Packet *p, int offset);
#define ADV_CHAR             ‘A’
#define REQ_CHAR             ‘R’
#define DATA_CHAR            ‘D’
#endif
********************************************************************
 And following into ns-default.tcl (line 765) to suppress few warnings:
 ********************************************************************
# ——————————————————
Phy/WirelessPhy set alive_ 1
Phy/WirelessPhy set Efriss_amp_ 100e-12
Phy/WirelessPhy set Etwo_ray_amp_ 0.013e-12
Phy/WirelessPhy set EXcvr_ 50e-9
Phy/WirelessPhy set sleep_ 0
Phy/WirelessPhy set ss_ 1
Phy/WirelessPhy set dist_ 0
# ——————————————————
********************************************************************
Now run the following the commands to re-compile ns in terminal.
make clean
make depend
make
 If the above commands passed successfully then you are ready to test your “Leach” by running “./test_leach” command.
 ./test_leach
Now go to the following directory “yourpath/ns-allinone-2.34/ns-2.34/ns-234-leach/mit/leach_sims” and check the file “leach.err”,
You may get few errors in the leach.err file as follows:
********************************************************************
can’t read “env(RCA_LIBRARY)”: no such variable
    while executing
“source $env(RCA_LIBRARY)/ns-ranode.tcl”
    (file “mit/uAMPS/sims/uamps.tcl” line 9)
      ………………….
      …..Code Omitted…..
      ………………….
      (procedure “source” line 8)
    invoked from within
“source tcl/mobility/$opt(rp).tcl”
    (file “tcl/ex/wireless.tcl” line 187)
********************************************************************
The problem is in the path. What modify all the paths in “ns-allinone-2.34/ns-2.34/mit/uAMPS/sims/uamps.tcl”. Here is the modified code below the commented out lines (lines beginning with ‘#’):
Code:
********************************************************************
############################################################################
#
# This code was developed as part of the MIT uAMPS project. (June, 2000)
#
############################################################################
global opt bs
#source $env(RCA_LIBRARY)/ns-ranode.tcl
source /home/arun/ns/ns-allinone-2.35-RC4/ns-2.35/mit/rca/ns-ranode.tcl
#source $env(uAMPS_LIBRARY)/ns-bsapp.tcl
source /home/arun/ns/ns-allinone-2.35-RC4/ns-2.35/mit/uAMPS/ns-bsapp.tcl
#source $env(uAMPS_LIBRARY)/extras.tcl
source /home/merom/ns-allinone-2.35-RC4/ns-2.35/mit/uAMPS/extras.tcl
#source $env(uAMPS_LIBRARY)/stats.tcl
source/home/arun/ns/ns-allinone-2.35-RC4/ns-2.35/mit/uAMPS/stats.tcl
#Uncomment these lines to use gdb to debug the c code
#source mit/uAMPS/ns-bsapp.tcl
#source mit/uAMPS/extras.tcl
#source mit/uAMPS/stats.tcl
#source $env(RCA_LIBRARY)/resources/ns-resource-manager.tcl
source /home/arun/ns/ns-allinone-2.35-RC4/ns-2.35/mit/rca/resources/ns-resource-manager.tcl
#source $env(RCA_LIBRARY)/resources/ns-energy-resource.tcl
source /home/arun/ns/ns-allinone-2.35-RC4/ns-2.35/mit/rca/resources/ns-energy-resource.tcl
#source $env(RCA_LIBRARY)/resources/ns-neighbor-resource.tcl
source /home/arun/ns/ns-allinone-2.35-RC4/ns-2.35/mit/rca/resources/ns-neighbor-resource.tcl
********************************************************************
Now run the following the commands to re-compile ns in terminal.
make clean
make depend
make
and execute following again: ./test_leach
Now check the file “leach.err”, if no error reported then go to “leach.out”  for results!

 

 

run again all commands it will work 🙂

for more please refer

http://forum.wsnlab.ir/pdf/LEACH.inNS2.wsnlab.ir.pdf

 

Error in installing NS2

Hello ,

errors while installing ns2

can’t find X includesotcl-1.13 configuration failed! Exiting …Please check http://www.isi.edu/nsnam/ns/ns-problems.html

solutions for that :

please copy and paste in shell

sudo apt-get install xorg-dev
sudo apt-get install libx11-dev
sudo apt-get install libxt-dev

Enjoy :)

|   

How to recover your blog password

Hello , Friends

i have a website which is hosted be wordpress  , i updated my wordpress from 3.5 to newer version but from that time i was not able to access the my wp-admin menu .

i googled a little bit then i didn’t get any thing then  i tricked with my website ……

1. i downloaded everything from my hosting place to my computer through filezila

2. the i made some changes in files  “admin.functions.php” in “upgrade-functions.php”  .

changes was i added

wp_set_password('password',1);

Put in your own new password for the main admin user. The “1” is the user ID number in the wp_users table.

3. Upload the modified file back to your site.

4. After you then are able to login, make sure to go back and remove that code. It will reset your password on every page load until you do.

 

Cheers !!!

 

Timers in NS2

If you are learning ns2, timers are often an obstacle. They concern with the ability of calling classes methods in consequence of an event schedule. The difficult raises when trying to find out in which order methods are called. If timers are involved, you can’t expect to find nested calls of methods until the one you are interested in. In this section it is explained how to understand this behavior.

A TimeHandler, as name suggests, is an object created to manage time, and is defined in the common/timer-handler(.cc,.h) files of your ns2 distribution. This handler is in charge to schedule the execution of events during the simulation. The time the handler refers to is the simulation time, not depending on the time your machine uses to process the code.
A timer is like a state machine and is charachterized by three states. The first is TIMER_IDLE which means that timer can manage an event. The next state is TIMER_PENDING, describing a status in which the timer is waiting to manage an event, and so it can’t accept new events. This means that the timer has accepted to manage an event to be scheduled in the future and it is busy, waiting for this event. The last state is TIMER_HANDLING in which the event is processed, calling the expire() function. After processing the event, timer returns in idle state.
In cbr/cbr-module(.cc,.h) of the MIRACLE distribution you can find a simple timer example, exploited to manage CBR packets transmission.
In the header file we define a new TimerHandler object. It is NOT possible to use TimerHandler class as is, because each timer has to handle its events in a particular fashion, which depends on the content of expire() function.

/**
 * Timer used by CbrModule to schedule packet transmission
 */
class SendTimer : public TimerHandler
{
public:
  SendTimer(CbrModule *m) : TimerHandler() { module = m; }

protected:
virtual void expire(Event *e);
CbrModule* module;
};

We defined the constructor, the expire() function and a reference to the module the timer refers to.
On the other side, when defining CbrModule, we have to add SendTimer_ as a friend class, in order to make it able to properly manage events. In this case expire() function has to call a CbrModule private method to activate packet sending processes.

  friend class SendTimer;

It is also necessary to define (in CbrModule) the timer itself, to have a reference to the object to whom submit events.

  SendTimer sendTmr_;  /*timer which schedules packet transmissions*/

In CbrModule.cc file, when you define the module constructor you have also to activate Timer constructor. This one has a reference to this to definitively associate SendTimer to this CbrModule. If you look at the definition of timer constructor, you’ll see that it only associates a CbrModule to the object (the one which submits events) to be managed by the timer.

CbrModule::CbrModule() 
  : sendTmr_(this),

At the top of the same file there is the definition of expire() function. When timer switchs to the TIMER_HANDLING state, it refers to this particular set of actions. When a CbrModule event expires, the function transmit() is called. Note that this function is defined in CbrModule, so Timer class has to be declaredas a friend of Module one. The module attribute refers to CbrModule, as explained before (see the constructor).

void SendTimer::expire(Event *e)
{
  module->transmit();
}

Now we are ready to schedule an event. TimerHandler class offers two methods to do this. They work in a similar fashion: both of them schedule an event but, while one is made to be called occasionally (i.e., when the timer is not busy, TIMER_IDLE), the second is created to work in an always pending status, in order to consecutively recall expire() function. If timer is always in TIMER_PENDING status, no other (sporadic) events can be managed by the timer. The former is called sched() and the latter is called resched(). The sched() function works only if timer is TIMER_IDLE while resched() can potentially cancel a previously scheduled TIMER_PENDING event and to schedule its new event. In this way the timer is maintaned always busy for those methods which don’t call resched() function. If your method instead, has the privileged resched() call you can access and modify the events.
In CbrModule we want to periodically transmit a packet. To achieve this result we use resched() function.

void CbrModule::start()
{
  ...
  sendTmr_.resched(period_);
}

At the end of transmit() method we reschedule again an event in order to create a “self-updating” loop. In this case, at the end of expire function, we schedule the timer for next period_ instants, maintaining the loop.

Thanx to ns-miracles for this post

Understanding “extern” keyword in C

Hello , one more important stuff to understand

I’m sure that this post will be as interesting and informative to C virgins (i.e. beginners) as it will be to those who are well versed in C. So let me start with saying that extern keyword applies to C variables (data objects) and C functions. Basically extern keyword extends the visibility of the C variables and C functions. Probably that’s is the reason why it was named as extern.

Though (almost) everyone knows the meaning of declaration and definition of a variable/function yet for the sake of completeness of this post, I would like to clarify them. Declaration of a variable/function simply declares that the variable/function exists somewhere in the program but the memory is not allocated for them. But the declaration of a variable/function serves an important role. And that is the type of the variable/function. Therefore, when a variable is declared, the program knows the data type of that variable. In case of function declaration, the program knows what are the arguments to that functions, their data types, the order of arguments and the return type of the function. So that’s all about declaration. Coming to the definition, when we define a variable/function, apart from the role of declaration, it also allocates memory for that variable/function. Therefore, we can think of definition as a super set of declaration. (or declaration as a subset of definition). From this explanation, it should be obvious that a variable/function can be declared any number of times but it can be defined only once. (Remember the basic principle that you can’t have two locations of the same variable/function). So that’s all about declaration and definition.
Now coming back to our main objective: Understanding “extern” keyword in C. I’ve explained the role of declaration/definition because it’s mandatory to understand them to understand the “extern” keyword. Let us first take the easy case. Use of extern with C functions. By default, the declaration and definition of a C function have “extern” prepended with them. It means even though we don’t use extern with the declaration/definition of C functions, it is present there. For example, when we write.

    int foo(int arg1, char arg2);

There’s an extern present in the beginning which is hidden and the compiler treats it as below.

    extern int foo(int arg1, char arg2);

Same is the case with the definition of a C function (Definition of a C function means writing the body of the function). Therefore whenever we define a C function, an extern is present there in the beginning of the function definition. Since the declaration can be done any number of times and definition can be done only once, we can notice that declaration of a function can be added in several C/H files or in a single C/H file several times. But we notice the actual definition of the function only once (i.e. in one file only). And as the extern extends the visibility to the whole program, the functions can be used (called) anywhere in any of the files of the whole program provided the declaration of the function is known. (By knowing the declaration of the function, C compiler knows that the definition of the function exists and it goes ahead to compile the program). So that’s all about extern with C functions.
Now let us the take the second and final case i.e. use of extern with C variables. I feel that it more interesting and information than the previous case where extern is present by default with C functions. So let me ask the question, how would you declare a C variable without defining it? Many of you would see it trivial but it’s important question to understand extern with C variables. The answer goes as follows.

    extern int var;

Here, an integer type variable called var has been declared (remember no definition i.e. no memory allocation for var so far). And we can do this declaration as many times as needed. (remember that declaration can be done any number of times) So far so good. :)
Now how would you define a variable. Now I agree that it is the most trivial question in programming and the answer is as follows.

    int var;

Here, an integer type variable called var has been declared as well as defined. (remember that definition is the super set of declaration). Here the memory for var is also allocated. Now here comes the surprise, when we declared/defined a C function, we saw that an extern was present by default. While defining a function, we can prepend it with extern without any issues. But it is not the case with C variables. If we put the presence of extern in variable as default then the memory for them will not be allocated ever, they will be declared only. Therefore, we put extern explicitly for C variables when we want to declare them without defining them. Also, as the extern extends the visibility to the whole program, by externing a variable we can use the variables anywhere in the program provided we know the declaration of them and the variable is defined somewhere.
Now let us try to understand extern with examples.
Example 1:

int var;
int main(void)
{
   var = 10;
   return 0;
}

Analysis: This program is compiled successfully. Here var is defined (and declared implicitly) globally.
Example 2:

extern int var;
int main(void)
{
  return 0;
}

Analysis: This program is compiled successfully. Here var is declared only. Notice var is never used so no problems.
Example 3:

extern int var;
int main(void)
{
 var = 10;
 return 0;
}

Analysis: This program throws error in compilation. Because var is declared but not defined anywhere. Essentially, the var isn’t allocated any memory. And the program is trying to change the value to 10 of a variable that doesn’t exist at all.
Example 4:

#include "somefile.h"
extern int var;
int main(void)
{
 var = 10;
 return 0;
}

Analysis: Supposing that somefile.h has the definition of var. This program will be compiled successfully.
Example 5:

extern int var = 0;
int main(void)
{
 var = 10;
 return 0;
}

Analysis: Guess this program will work? Well, here comes another surprise from C standards. They say that..if a variable is only declared and an initializer is also provided with that declaration, then the memory for that variable will be allocated i.e. that variable will be considered as defined. Therefore, as per the C standard, this program will compile successfully and work.
So that was a preliminary look at “extern” keyword in C.
I’m sure that you want to have some take away from the reading of this post. And I would not disappoint you. :)
In short, we can say
1. Declaration can be done any number of times but definition only once.
2. “extern” keyword is used to extend the visibility of variables/functions().
3. Since functions are visible through out the program by default. The use of extern is not needed in function declaration/definition. Its use is redundant.
4. When extern is used with a variable, it’s only declared not defined.
5. As an exception, when an extern variable is declared with initialization, it is taken as definition of the variable as well.

Copied from GeekforGeeks Thanx GeekforGeeks.

Hi Guys

Hi Guys , December was the holiday time , in this  winter i decided to studied Python ,that is very Good Scripting LAnguage , this helps us in very different ways … i will put some lecture videos and some assignments this will help you guys .

 

All the BesT !! 🙂