Function Pointers inside Struct in C

#include <stdio.h>

typedef struct{
	int x;
	int y;
	int (*addXPoints) (int x,int y);
	int (*subXPoints) (int x,int y);
}Point;

int addPoints_x(int p1, int p2)
{
		return (p1+p2);
}	

int subtracteXPoints(int p1,int p2)
{
		return (p1-p2);
}

void printPointDetails(Point* temp)
{
		printf("Point [x,y] : %d , %d \n", temp->x, temp->y);
}

int main()
{
	Point p1={30,30};
	
	//another way to initialize
	//p1.x=10; 
	//p1.y=20;
	p1.addXPoints=addPoints_x;
	p1.subXPoints=subtracteXPoints;
	
	printPointDetails(&p1);
	
	printf("Total X Value of p1,p2 : %d\n",p1.addXPoints(p1.x,p1.x));
	printf("Total X Value of p1,p2 : %d\n",p1.subXPoints(p1.x,p1.x));
	

	return 0;
}

Constant pointers and Pointers to constant in C

#include <stdio.h>
int main()
{
	int val = 250;
	int val2 =300;

        // ptrInt is a pointer to integer constant
        const int* ptrInt = &val; //Pointer to Constant

        // ptrInt1 is a constant pointer to integer
        int* const ptrInt1 = &val; //Constant Pointer

        *ptrInt = 500; //pointer to constant wont allow

	ptrInt1 = &val2; //constant pointer wont allow

	return 0;
}

Rooting Lava Xtron android tablet

WARNING : It worked for me but still, do at your our risk. 

Lava Xtron is the only cheapest android tablet which has performance equalling nexus 7.  See the flipkart link below for more details

http://www.flipkart.com/lava-e-tab-xtron-tablet/p/itmdgjwxm7zfpxwc?pid=TABDHVNGHZGHYNME&ref=e7fa0475-6e55-491a-a704-9565f7810e15&srno=t_1&otracker=from-search&query=lava%20xtron

But the problem is that you dont get usb drivers for connecting it to your windows pc. More worse for developers, since it is impossible to perform adb tasks, app debugging ,etc.

Just follow these steps to root your xtron tablet.

A . Getting USB drivers

1.First, we need usb drivers so that our device gets detected.Install Moborobo which is an software for managing your device sms,videos,pics,etc

http://www.moborobo.com/products/moborobo.html

2.After installing it, connect your tablet and wait for it check your device for downloading necessary drivers.

3.Once connected vid USB, you should be able to see your device files, sd-card size in the moborobo desktop application.

NOTE : In moborobo software, Device model of the tablet will not be shown when detected. Its just a bug.Ignore it.

B . Rooting the device

1. Download the software  ZhuoDaShi-2.2.0-setup.exe . Sometimes your antivirus might block this. Deal with them.

https://hotfile.com/dl/165309989/766c52f/ZhuoDaShi-2.2.0-setup.exe.html

2.Since it is a japanese/chinese software, you may see some crazy instrution text while installing. Follow the screenshots below…

Installcaption

Screen 1

Screen 2

Screen 2

Screen 3

Screen 3

Screen 4

Screen 4

Screen 5

Screen 5

Screen 6

Screen 6

Screen 7: Installation is done

Screen 7: Installation is done

Screen 8 : This is the main screen. Click the mentioned icon

Screen 8 : This is the main screen. Click the mentioned icon. My AV is sneeking around..:-/..dont mind it

Screen 9 : When clicked, an app is intalled and opened on your device. You dont need to select anything on your device screen. Just follow the desktop instructions

Screen 9 : When clicked, an app is intalled and opened on your device. You dont need to select anything on your device screen. Just follow the desktop instructions

Screen 10: Click  root. On the next screen, you will see the script in action.

Screen 10: Click root. On the next screen, you will see the script in action.

Screen 11: At last ,rooting is done.

Screen 11: At last ,rooting is done.

Go to Play and download any root checking software to confirm your root status. Thats it….

Update: This tablet is out of production(Incase, you are planning to buy :/ )

Login application using Java Swings and Mysql.

Front-end:Java Swings

Back-end:MySql

Class 1:Login JFrame

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class swing_sample extends JFrame
{
	//declaring our swing components
	JLabel l_name,l_pass;
	JTextField t_name;
	JPasswordField t_pass;     //A special JTextField but hides input text
	JButton button;
	Container c;

	//a inner class to handling ActionEvents
	handler handle;

	//a separate class for processing database connection and authentication
	database db;

	swing_sample()
	{
		super("Login form");

		c=getContentPane();
		c.setLayout(new FlowLayout());

		//extra classes
		db=new database();
	        handle =new handler();

                //swing components
		l_name=new JLabel("Username");
		l_pass=new JLabel("Password");
		t_name=new JTextField(10);
		t_pass=new JPasswordField(10);
		button=new JButton("Login");

		//adding actionlistener to the button
		button.addActionListener(handle);

		//add to contaienr
		c.add(l_name);
		c.add(t_name);
		c.add(l_pass);
		c.add(t_pass);
		c.add(button);
		//visual
		setVisible(true);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(200,130);

	}
	public static void main(String args[])
	{
		swing_sample sample=new swing_sample();
	}

	//an inner class .You can also write as a separate class
	class handler implements ActionListener
	{
		//must implement method
		//This is triggered whenever the user clicks the login button
		public void actionPerformed(ActionEvent ae)
		{
			//checks if the button clicked
			if(ae.getSource()==button)
			{
				char[] temp_pwd=t_pass.getPassword();
				String pwd=null;
				pwd=String.copyValueOf(temp_pwd);
				System.out.println("Username,Pwd:"+t_name.getText()+","+pwd);

				//The entered username and password are sent via "checkLogin()" which return boolean
				if(db.checkLogin(t_name.getText(), pwd))
				{
					//a pop-up box
					JOptionPane.showMessageDialog(null, "You have logged in successfully","Success",
                                        JOptionPane.INFORMATION_MESSAGE);
				}
				else
				{
					//a pop-up box
					JOptionPane.showMessageDialog(null, "Login failed!","Failed!!",
                                        JOptionPane.ERROR_MESSAGE);
				}
			}//if
		}//method

	}//inner class
}//class

Class 2:Database

This is where the validation takesplace.
Connects to mysql and validates the username and pwd.

Note:Make sure you set the classpath to point the mysql_connector.jar file.The program wont work without it.

Download from mysql site by searching “Jconnector”.

import java.sql.*;
public class database 
{
	Connection con;
	PreparedStatement pst;
	ResultSet rs;
	database()
	{
		try{
			
			//MAKE SURE YOU KEEP THE mysql_connector.jar file in java/lib folder
			//ALSO SET THE CLASSPATH
			Class.forName("com.mysql.jdbc.Driver");
			con=DriverManager.getConnection("jdbc:mysql://localhost:3306/ajax","root","");
                        pst=con.prepareStatement("select * from biodata where uname=? and pwd=?");
			
		   }
		catch (Exception e) 
		{
			System.out.println(e);
		}
	}
        //ip:username,password
        //return boolean
	public Boolean checkLogin(String uname,String pwd)
	{
		try {
                       
			pst.setString(1, uname); //this replaces the 1st  "?" in the query for username
			pst.setString(2, pwd);    //this replaces the 2st  "?" in the query for password
			//executes the prepared statement
			rs=pst.executeQuery();
			if(rs.next())
			{
				//TRUE iff the query founds any corresponding data
				return true;
			}
			else
			{
				return false;
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			System.out.println("error while validating"+e);
			return false;
		}
}

Output Screen:

 

Back:JFrame(Input window) Front:JOptionPane(confirmation window)

 

Hello world!

Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!