Wednesday, July 18, 2012

Logic Thinking

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

int main()
{
#define HAPPY (1)
#define SATISFIED (1)
if(!HAPPY != SATISFIED)
{
printf("Life");
}
else
{
printf("Heaven");
}

getch();
return 0;
}

Output:



Its in Your Hand


Ans: Life

Wednesday, June 20, 2012

C PreProcessor and Intermediate C Code

# include <stdio.h>
# include <windows.h>

# define MAX 10


int main()
{
 static int nVariabe; // To understand the static variable constant
 int nloop=0;

    for (;nloop<MAX;nloop++)
    {
        nVariabe++;
        printf("%d static variable %d\n",nloop,nVariabe);

    }

 return 0;

}

 Please Check the For Condition .
From this code you will get the intermediate code information and understanding the C Macros.

Output for intermediate C code Generation




Static Variable Declaration without Data Type

# include <stdio.h>
# include <windows.h>

# define MAX 10


int main()
{
 static nVariabe; // To understand the static variable constant
 int nloop=0;

    for (;nloop<MAX;nloop++)
    {
        nVariabe++;
        printf("%d static variable %d\n",nloop,nVariabe);

    }

 return 0;

}

OUTPUT:

Here, everybody feels like compilation will abort. But, actual result is below,.
0 static variable 1
1 static variable 2
2 static variable 3
3 static variable 4
4 static variable 5
5 static variable 6
6 static variable 7
7 static variable 8
8 static variable 9
9 static variable 10

Note: We will get only Warning....

Description    Resource    Path    Location    Type
type defaults to `int' in declaration of `nVariabe'    Code.c    /intermediateCode    line 17    C/C++ Problem

Saturday, March 24, 2012

User File Browser in VBA

Sub User_FileBrowser()

Dim varFileName As Variant
Dim nLoop As Integer

'For single file selction
'varFileName = Application.GetOpenFilename(, , "Please select source workbook:")

'For Multiple file selection
varFileName = Application.GetOpenFilename(FileFilter:="Excel files (*.xls), *.xls", Title:="Please select source workbook:", MultiSelect:=True)
nLoop = 1


Do

If TypeName(varFileName(nLoop)) = "String" Then
Cells(2, 2).Value = varFileName(nLoop)
Else

MsgBox "Please Select the xls file", vbOKOnly, "Warning!"
Exit Sub

End If

nLoop = nLoop + 1
Loop Until nLoop = UBound(varFileName)

End Sub

How to create message Box2 in VBA

Sub Msg_Box()


MsgBox "Testbox", vbYesNo, "karthiken07"

OutPut
End Sub

How to create message Box in VBA

1.Create Command button using form tool bar.

Sub Msg_Box()


MsgBox "Testbox"

End Sub

Output :

Friday, December 30, 2011

Factorial using while loop

/*
* Factorial.c

*
* Created on: Dec 30, 2011
* Author: karthikeyan
*/

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

int main()
{
int nFact;
int nFactSum=1;
int nLoop;

printf("Enter the factorial numbers\n");

scanf("%d",&nFact);

nLoop = nFact;

while(nLoop > 1)
{
nFactSum = nFactSum * nLoop;

nLoop--;

}

printf("Factorial Value of %d! is :: %d",nFact,nFactSum);



return 0;
}

OUTPUT:

Enter the factorial numbers
5
Factorial Value of 5! is :: 120

Tuesday, November 1, 2011

How to create Dll and How to call dll function

/**********************************************************************************
* Exe.c
*
* Created on: Oct 12, 2011
*
**********************************************************************************/

# include <stdio.h>
# include <stdlib.h>
# include <windows.h>

int main()
{
//To Load the Dll files
HINSTANCE CallDll=NULL;
FARPROC FunctionLoad;
CallDll = LoadLibrary("D:\\WorkSpace\\DLL_File_Creation\\Debug\\libDLL_File_Creation.dll");
FunctionLoad =GetProcAddress(CallDll,"FirstCallFunction");

FunctionLoad();

FreeLibrary(CallDll);
return 0;
}

/**********************************************************************************
* DLL_File_Creation.c
*
* Created on: Oct 12, 2011
*
**********************************************************************************/

# include <stdio.h>
# include <stdlib.h>
# include <windows.h>

int FirstCallFunction();
/*
* This Function is used to understand the Dll calling process.
*/
int FirstCallFunction()
{

printf("I am in Dll First Call Function \n");
MessageBox(0,"Information","I am in Dll First Call Function ",2);

return 0;
}

Monday, October 17, 2011

Hibernate in XP system

1. Hibernate shortcut -> Please make sure you have Hibernate turned on.

2. Go to the Control panel then click Performance and maintenance. Next, choose Power options, and select the hibernate tab.

3. Finally, make sure Enable hibernation is checked.





4. Please make the shortcut right click your desktop and choose New | Shortcut. Next, type this case-sensitive command into the dialog box rundll32.exe PowrProf.dll, SetSuspendState


5. click next. Give the shortcut a name and click finish.

6. From now on all you need to do to enter hibernation is double click the shortcut.

Thursday, April 7, 2011

xml file tokenizing in c coding

//header files
# include "stdio.h"
# include "string.h"
# include "stdlib.h"

//FunctionDeclaration
int YourFunction(char**,char*,char*);

//Global variable
char *cPagexml = "<root><device><producer>Indian politician</producer><problem>barrier for india's growth </problem></device></root>";

int main()
{
//Variable Declaration
char *TagName = "producer";
char *xml = NULL;
char *Tagvalue = "public must react about it";

//Memory allocation
xml = (char *)calloc(1024,1);

//To copy the xml file
strcpy(xml,cPagexml);

printf("Fist Time : %s\n\n\n",xml);

//Call function
YourFunction(&xml,TagName,Tagvalue);


printf("After your function : %s\n\n\n\n",xml);

return 0;

}

/****************************** function definition ****************************************
User want to write this function to get the output


***********************************************************************************************/

int YourFunction(char**xml,char*TagName,char*TagValue)
{
//Variable declartion
int nCount,nLoop;
int nTagValueLength;
int nLength;
char *cTempdata = (char *)calloc(1024,1);
char *cTemp = (char *)calloc(1024,1);
char *tempvalue=NULL;


// To move the pointer to producer
cTemp = strstr(*xml, TagName);

//To count the number of character pointer moved
nCount = (int)( cTemp - *xml);

// Cut the first ncount char from source
strncpy(cTempdata,*xml,nCount);

//to assign to other variable
nLoop = nCount;
// To reach the crrent position as tag
while(nLoop != 0)
{
nLoop--;
*cTempdata++;
}


// to reach the end of the tag name
while (*cTemp != '>')
{
// to assign in new pointer
*cTempdata++ = *cTemp++;
nCount++;
}
//for > symbol
*cTempdata++ = *cTemp++;
nCount++;

tempvalue = strstr(cTemp,TagName);
nTagValueLength = strlen(TagValue);
nLength = tempvalue - cTemp;
nLength -=2; //for </ symbols of end tag

if(nTagValueLength <= nLength)
{

while (*TagValue != '\0')
{
*cTempdata++ = *TagValue++;
*cTemp++;
++nCount;
}

nLength = (nLength-nTagValueLength);

while (nLength !=0)
{
nLength--;
*cTemp++;
}
}
else
{
while (*TagValue != '\0')
{
*cTempdata++ = *TagValue++;

++nCount;
}
while(nLength-- != 0)
*cTemp++;



}



while (*cTemp != '\0')
{

*cTempdata++ = *cTemp++;
nCount++;
}



// for reassigning the contents

nLoop = nCount;
while (nLoop--!= 0)
{
cTempdata--;
}

// To reassign the value to xml pointer
strcpy(*xml,cTempdata);


return 0;
}




OUTPUT:

Fist Time : <root><device><producer>Indian politician</producer><problem>barrier for india's growth </problem></device></root>


After your function : <root><device><producer>public must react about it</producer><problem>barrier for india's growth </problem></device></root>



Press any key to continue . . .





Indian Economy: Performance and Policies