C/C++
Binary to decimal and decimal to binary conversion in C
This program will show you to convert a binary to decimal and vice versa.
This will take a character array input which is the binary value. Then it will convert the binary value to decimal and then convert it again from decimal to binary. Here is the code.
No CommentsHow to connect to mysql database using ANSI C language
This is a sample program which connect to mysql database using in c programming.
#include<stdio.h>
#include<mysql/mysql.h>
#include<stdlib.h>
int main(int argc, char *argv[])
{
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char *server ="localhost";
char *user = "root";
char *password = "123456";
char *database = "dsc";
conn = mysql_init(NULL);
// Connect to database
if(!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0))
{
fprintf(stderr, "%s\n", mysql_error(conn));
exit(1);
}
// sql query
if(mysql_query(conn, "select * from dsc_scripts"))
{
fprintf(stderr, "%s\n", mysql_error(conn));
exit(1);
}
res = mysql_use_result(conn);
//output table name
printf("Mysql Tables in mysql database: \n");
while((row = mysql_fetch_row(res)) !=NULL)
printf("%-3s%-30s%-30s\n", row[0], row[1], row[2]);
// close connection
mysql_free_result(res);
mysql_close(conn);
return 0;
}
No CommentsGenerate prime number using seive function in c
This is a sample of how to generate prime numbers can be generated using seive method. This is a sample code written in c. It will generate prime numbers and save them to a file. It will generate all primes upto 10000000. These codes are commented well to show how effeciency of this program has been increased
No CommentsSend SMS through a c program
Ya! You can! You can send an sms from your computer to any mobile using 3 lines of codings in c program!
Dont beleave?? Okay lets have a try…
First you should have gnokii package installed in your computer. Gnokii is a library for written in c to communicate with mobile phones from your computer. I tested this only on my ubuntu 9.04 so I don what windows users should do here.
1 CommentCreate a window using window.h in c
This sample code will create a basic window using window.h in c language
#include <windows.h>
const char g_szClassName[] = "myWindowClass";
// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;
//Step 1: Registering the Window Class
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
// Step 2: Creating the Window
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"The title of my window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 640, 480,
NULL, NULL, hInstance, NULL);
if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
// Step 3: The Message Loop
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
No CommentsEclidean GCD by Substraction
Euclidean GCD is a method or algorithm for calculating GCD (Greatest Common Divisor). I implemented this in C. To know details about euclidean gcd visit details of this methon in wikipedia
http://en.wikipedia.org/wiki/Euclidean_algorithm
No Comments
