Header menu

_________________________________________________________________________________

Wednesday, 6 September 2017

Type Conversion in expressions in C

When constants and variable of different types are mixed in an expression, they are converted to the same type . The C compiler will convert all operands to the type of largest operand. This is done on an operation by operation basis following type conversion rules.

1. All chars and short int are converted to int. All floats are converted to doubles.

2. For all operand pairs: if one of the operands is double, the other operand is converted to double. Otherwise, if one of the operands is long, the other operand is converted to long.; if one of the operands is unsigned, the other is converted to unsigned

Tuesday, 5 September 2017

How to use Extern in C ? / How to use same global variable in multiple files ?

If you try to declare two global variables with the same name your c compiler will print the error message duplicate variable name, which means that the compiler does not know which variable you are using at any one moment. The same type of problem occurs if you simply declare all yours global variables in each  file. you would actually be trying to create two copies of each variable. When you attempt to link your modules together you will get error message duplicate label.

The solution is to declare all of your global variables in one file and use extern-modified declaration in other files

As illustrated below:

First we create a file with global variables 

fileb.c

int a=100;
int b=200;

Now we use these global variables in other file.

file.c

#include<stdio.h>
#include<conio.h>
#include<D:\inputs\fileb.c>
extern int a;
extern int b;
int main()
{

    printf("This is main file and a & b are called from other file\n");
    printf("The value of A and B from other file is %d and %d",a,b);
    getch();
    return 0;
}

OUTPUT 

This is main file and a & b are called from other file
The value of A and B from other file is 100 and 200
 

Sunday, 3 September 2017

Use of %C, %d, %e, %f, %s in printf

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<conio.h>
int main()
{
    //"Use of %C, %d, %e, %f, %s  in printf
   
    char ch='A';                                                              // single quote is used for char
    printf("The char enttered is %c",ch);
    int i=1001;
    printf("\n The integer enttered is %d",i);
    double j=3454000;
    printf("\n The integer enttered in scientific notation is %e",j);  
    float f=34.546;
    printf("\n The float enttered is %f",f);  
    char s[] = "Welcome to codesplanet.blogspot.in";        // double quote is used for string
    printf("\n The string entered is : %s",s);
  
    getch();
    return 0;
    }

Multiplication in C

#include<stdio.h>
#include<conio.h>
int main()
{
    int i=14;
    int j=15;
    int k=i*j;
    printf(" The product is %d",k);
    getch();
    return 0;
    }

Saturday, 2 September 2017

Hello World !! in C++

#include<iostream>
#include<stdio.h>
#include<conio.h>

using namespace std;
int main()
{
    cout<< "Hello World! Welcome to C++";
    getch();
    return 0;
    }

Tuesday, 21 April 2015

Error when trying to access XAMPP from a network in windows


Error when trying to access XAMPP from a network in windows

Access to the requested object is only available from the local network. This setting can be configured in the file  "httpd-xampp.conf".

This solution will work in latest version of XAMPP

1.) Go to C:\xampp\apache\conf\extra
2.) Open httpd-xampp
3.) Look for 


#
# New XAMPP security concept
#
<LocationMatch "^/(?i:(?:xampp|security|licenses|phpmyadmin|webalizer|server-status|server-info))">
        Require local
    ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</LocationMatch>
4.) Remove them
5.) Restart Xampp

You are done 

Tuesday, 30 September 2014

Auto-click function for facebook login button using javascript


  

Auto-click function for  facebook login button using javascript

(Function to initialize facebook login process)


I have added facebook sign button on my website. On clicking on it i can make user to login in my application using facebook account.

Now i want to click on some other button and want to initialize facebook login functionality .

To do so i need 2-3 lines of code / a function to start login process.

function facebookLogin() {
    FB.login(function(response) {
        if (response.authResponse) {
        statusChangeCallback(response);
        //    console.log('Authenticated!');
            // location.reload(); //or do whatever you want
        } 
    },
    {
        scope: 'email,user_checkins'
    });
}
facebookLogin();


Auto-click function for google sign button using javascript


  

Auto-click function for  google sign button using javascript

(Function to initialize google sign process)

I have added google sign button on my website. On clicking on it i can make user to login in my application using google account.

Now i want to click on some other button and want to initialize google sign functionality .

To do so i need 2-3 lines of code / a function to start login process.

var myParams = {
    'clientid': 'your client-id',
    'cookiepolicy': 'single_host_origin',
    'callback': 'onSignInCallback',
    'scope': 'email'
};
gapi.auth.signIn(myParams);



Saturday, 9 August 2014

Ajax Simple Captcha on jquery Dialog form


 

Ajax  Simple Captcha on jquery Dialog form

CAPTCHA  is a type of challenge-response test used in computing to determine whether or not the user is human. Adding captcha to html/php page is simple task . But its not so easy in jquery dialog form for newbies . So lets implement a simple captcha for jquery dialog form.

I will use 4 files :
1. index.php ( Contains html form, javascript code to send ajax request)
2. captcha.php ( Create captcha image)
3. captcheck.php ( Check weather value entered for captcha is right or wrong)
4. post.php ( Page where form submits if captcha validation is fine)
index.php

Friday, 25 July 2014

Table data overflowing even after giving fixed width due some long string .


 

Table data overflowing even after giving fixed width due some long string .

After giving fixed width to table and column ,we suppose that we will get same type of table every time. But sometime due to some long string which is greater than width of column , table overflows of given width.

To tackle that problem add these two small lines to your style:



Firstly , give fixed layout out to table and secondly add word-wrap: break-word; property to column . And you are all done :)

Tuesday, 27 May 2014

Extract parameters from url using javascript or jquery in html file.


 

Parsing url in jquery or javascript to extract parameter from url in html file


If you are using a html file and you have to receive some parameters from url , then
below is the method you are looking for.

Only this you have to do ... is to call getUrlVars with field name to extract as done in this statement  :

var first_name = getUrlVars()["first_name"];  


Tuesday, 20 May 2014

In how ways you can add css to a html page ?


 

Methods to add css to html page :

We can add css to a page using 3 methods :

a) External css
b) Internal css 
c) Inline css 

External css : In this we make an css file and then call that file in our page using link .
      

Internal css : In this we write our css in head of the the html page using style tag.
               

Inline css : In this we add style to the element . 

The best method of adding css is external and the most powerful is inline because override    previous css included.

Thursday, 15 May 2014

Use of RedirectMatch 301 directive in htaccess.


 

Use of  RedirectMatch 301 directive in htaccess.

To redirect more than a single page using htaccess, you can use the "RedirectMatch 301" directive, which allows you to specify directory matching patterns using regular expressions.

Here  301 redirect is a permanent redirect method which passes between 90-99% of  ranking power to the new redirected page and (?i) signifies case insensitivity .

Point to remember:

1. (?i) starts case-insensitive mode
    (?-i) turns off case-insensitive mode

2.  /directory/cart   This is the directory which i am redirecting . When this directory structure will occur in url , page will be redirected to stated page.

3.   http://localhost/directory2?   This is my new address where i want page to be redirected.

Wednesday, 14 May 2014

Jquery not loading properly on clicking links in mobile site.


 

Jquery not loading properly on clicking links in mobile site.

Today while working on a mobile site , i went through a strange problem. Everything works well on site when i refresh page but when i click on links then my jquery and css are not loading properly. Resulting in improper design. After searching about the problem i came to know that on mobile jquery loads only on first page on all other pages its use preloaded js and css.

More you can read at : http://demos.jquerymobile.com/1.2.1/docs/pages/page-scripting.html

Now to solve this problem . I added rel='external'  to every link . Now whenever i click on link my jquery and css are loading properly.

Tuesday, 6 May 2014

How to get value of select box in Javascript/Jquery ?


 

Get value of select box in Javascript/Jquery

This is my select box.  And i want to get its value in javascript/jquery .

<select name="qt" class="qt" id='qt'>
<option value='0'>&nbsp;</option>
<option value='Newspaper'>Newspaper</option>
<option value='Facebook Ad'>Facebook Ad</option>
<option value='Google Search'>Google Search</option>
<option value='Other Internet Site'>Other Internet Site</option>
<option value='Test Prep Center'>Test Prep Center</option>
</select>

 To get its value i will use two lines.

var s = document.getElementById('qt');         /**qt is the id of select box**/
var selectval = s.options[s.selectedIndex].value; 

Working example:

Friday, 2 May 2014

PHP force file download method not working on android mobile when file path is passed from database


 

PHP force file download method not working on android mobile when file path is passed from database

When you use are using force download method of php to download some music/video on any android device ( I specifically performed for this ) . Then you might face two types of problems.

1.  You will get html page instead of media file.

2.  When you are passing file path from database, your file is not downloaded completely. It will show download complete after downloading some byte. In straight incomplete file is downloaded .

Below is the code that will work for solving these two problem. The points to remember are 

(a) Do not call download method from the loop where you are checking post or get request . Call download method out of GET/POST condition check loop. It is solve first problem of html pages download.

(b) Pass only file name from the database . Keep the file path static . I know this will make code hard coded but if you pass path from database then '/'  in path will create problem. And you will not be able to download file properly.



                                                I hope this will work for you too ..  :)

Sunday, 27 April 2014

Facebook javascript SDK returns undefined email in response


 

Facebook javascript SDK returns undefined email in response

Yesterday ,i was implementing login through Facebook option on my website . Initially everything went well . Then with no reasons facebook started returning undefined email ids.

If you are facing the same problem too , then there is two words solution for this . Add data-scope="email" in button.


Facebook javascript SDK returns undefined email in response

                                               I hope this will work for you too ..  :)

Monday, 21 April 2014

Javascript autosubmit form Error: submit() is not a function



 Submit() is not a function. 

 

This error occurs in javascript while auto submitting form when there exist an input field with name submit or input of the type submit in the html form.

To remove the error just change the name from submit to something else .Then your form will work flowless.

 

Error :


Form  giving error:



Corrected Form: [name submit removed]


Friday, 11 April 2014

InnoDB: mmap(137363456 bytes) failed; errno 12



* Error displaying the error page application instantiation error

* Error happens while site is running and mysql database  crashes . On reboot everything start working well again.

  Error logs

140410 9:16:44 [ERROR] Native table 'performance_schema'.'file_instances' has the wrong structure 140410
9:16:44 [Note] Event Scheduler: Loaded 0 events 140410 9:16:44 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.5.29-0ubuntu0.12.04.2' socket: '/var/run/mysqld/mysqld.sock' port: 3306 (Ubuntu) 140410 21:26:53 [Note] Plugin 'FEDERATED' is disabled.
140410 21:26:53 InnoDB: The InnoDB memory heap is disabled
140410 21:26:53 InnoDB: Mutexes and rw_locks use GCC atomic builtins 140410 21:26:53 InnoDB: Compressed tables use zlib 1.2.3.4
140410 21:26:53 InnoDB: Initializing buffer pool, size = 128.0M InnoDB: mmap(137363456 bytes) failed; errno 12
 140410 21:26:53 InnoDB: Completed initialization of buffer pool
140410 21:26:53 InnoDB: Fatal error: cannot allocate memory for the buffer pool
140410 21:26:53 [ERROR] Plugin 'InnoDB' init function returned error.
140410 21:26:53 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
140410 21:26:53 [ERROR] Unknown/unsupported storage engine: InnoDB 140410 21:26:53 [ERROR] Aborting
140410 21:27:08 [Note] Plugin 'FEDERATED' is disabled.
140410 21:27:08 InnoDB: The InnoDB memory heap is disabled
140410 21:27:08 InnoDB: Mutexes and rw_locks use GCC atomic builtins 140410 21:27:08 InnoDB: Compressed tables use zlib 1.2.3.4
140410 21:27:09 InnoDB: Initializing buffer pool, size = 128.0M InnoDB: mmap(137363456 bytes) failed; errno 12
140410 21:27:09 InnoDB: Completed initialization of buffer pool
140410 21:27:09 InnoDB: Fatal error: cannot allocate memory for the buffer pool
140410 21:27:09 [ERROR] Plugin 'InnoDB' init function returned error.
140410 21:27:09 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
140410 21:27:09 [ERROR] Unknown/unsupported storage engine: InnoDB 140410 21:27:09 [ERROR] Aborting 140410 21:27:09 [Note] /usr/sbin/mysqld: Shutdown complete
140410 21:27:10 [Note] Plugin 'FEDERATED' is disabled.
140410 21:27:11 InnoDB: The InnoDB memory heap is disabled
140410 21:27:11 InnoDB: Mutexes and rw_locks use GCC atomic builtins 140410 21:27:11 InnoDB: Compressed tables use zlib 1.2.3.4
140410 21:27:11 InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap(137363456 bytes) failed; errno 12
140410 21:27:11 InnoDB: Completed initialization of buffer pool
140410 21:27:11 InnoDB: Fatal error: cannot allocate memory for the buffer pool
140410 21:27:11 [ERROR] Plugin 'InnoDB' init function returned error.
140410 21:27:11 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
140410 21:27:11 [ERROR] Unknown/unsupported storage engine: InnoDB 140410 21:27:11 [ERROR] Aborting 

This error might occur in InnoDB in two situation :

1. When InnoDB unable to allocate memory as specified in innodb_buffer_pool_size variable




And then reboot the system. If your problem is not solved by these steps , then look for you swap file.

2. Swap file not present .If swap file is not present you can create it by

Wednesday, 2 April 2014

Pass parameter to post method of file_get_contents()


If you are looking for some alternative to php cURL then file_get_contents is the function you are looking for. File_get_contents() is the  way to read the contents of a file into a string. We are going to discuss this function  as simple one to request data from server and then with post method to parameters requesting for some specific content. It is same as like CURL requesting server/service for some data.

In simplest form we can just pass url to function to get content of webpage:


To do more you can pass parameter as string to post method



At last passing array as parameter to post method of file_get_contents()