Posts

Showing posts from May, 2012

Get IP Address in C

/////////IP ADDRESS OF MY SYSTEM///////////// / /This programme will show you IP Address,Name,Host of your System   #include <stdio.h>  #include <WinSock.h>  #include <stdlib.h>  #pragma comment (lib, "wsock32.lib")  int main()  {   WORD wVersionRequested;   WSADATA wsaData;   char caHostname[255+1];   PHOSTENT hostData;   char *pIP;   int i=0;   wVersionRequested=MAKEWORD(1,1);   if(WSAStartup(wVersionRequested, &wsaData)!=0)   {    printf("Error......code is not compartible with platform\n");    exit(EXIT_FAILURE);   }   if(gethostname(caHostname, sizeof caHostname)!=0)    printf("Error......Hostname not found\n");   printf("HOSTNAME : %s\n",caHostname);   if((hostData=gethostbyname(caHostname))==NULL)   {    printf("Error......code is not compartible with platform\n");    exit(EXIT_FAILURE);   }   while(hostData->h_addr_list[i])   {    pIP =

Find Directory using C on Linux and Windows

#Find Files in Directory. ///////FIND FIRST///Only Work on  WINDOWS (O.S) ///////////// #include <stdio.h> #include <time.h> #include<string.h> #include<sys/io.h> int main(void) {     struct _finddata_t c_file;     long hFile;     char path[100]="D:\\sharjeel\\Messages\\";      strcat(path,"/*.wav");              hFile=_findfirst(path ,&c_file);     /* Find first .wav file in current directory */     if(hFile== -1L )        printf( "No *.wav files in current directory!\n" );    else    {             printf( "Listing of .wav files %s\n\n",c_file.name);             /* Find the rest of the .wav files */             while( _findnext( hFile, &c_file ) == 0 )             {                 printf( "Listing of .wav files %s\n\n",c_file.name);             }        _findclose( hFile );    } } //////////Below Written Function Will work on LINUX as well as WINDOS////////////// ->Sea

C with MySql Data Base on Linux

//////////////CONNECT C CODE WITH MYSQL///////////////// ->First we have to include MYSQL.h header file.Here we are using 4 pointers name as server, user, passward ,database and following are the compile and run command on LINUX O.S //////////With gcc compiler On LINUX O.S//////////// ->gcc -o filename $(mysql_config --cflags) filename.c $(mysql_config --libs) #include <stdio.h> #include <string.h> #include <stdlib.h> #include "/usr/include/mysql/mysql.h" main() {  MYSQL *conn;  MYSQL_RES *res = NULL;  MYSQL_ROW row;  char *server="localhost";           /*server name or ip on which you want to connect c code with mysql database*/  char *user = "root";                       /*user of that system*/  char *password ="XYZ";             /*password of user of that system*/  char *database = "sharjeel";     /*database name of that system on which you are connecting c code with mysql*/     char query[100]=