Sample:
INPUT:
netsh interface ip show address "Local Area Connection 2"
OUTPUT:
Wednesday, October 20, 2010
Tuesday, October 19, 2010
Sample make File
myprogram:
g++ stack.c -o stack.exe
g++ revfile.c -o revfile.exe
clean:
rm -rf *.o *.exe
g++ stack.c -o stack.exe
g++ revfile.c -o revfile.exe
clean:
rm -rf *.o *.exe
Friday, October 15, 2010
Memory Reference Problem
/*
* StruMem.c
*
* Created on: Oct 15, 2010
* Author: KArthikeyan.D
*
*/
# include <stdio.h>
# include <malloc.h>
# include <string.h>
typedef struct struture1
{
int a;
int b;
}stru;
int main()
{
stru *Memory = (stru*)malloc(sizeof(stru));
//Memory = NULL;
Memory->a=12;
Memory->b = 21;
free(Memory);
printf("%d ",Memory->b);
return 0;
}
Note: View last two lines. Memory freed . After that we are trying to get the value.
OutPut: Garbage value
* StruMem.c
*
* Created on: Oct 15, 2010
* Author: KArthikeyan.D
*
*/
# include <stdio.h>
# include <malloc.h>
# include <string.h>
typedef struct struture1
{
int a;
int b;
}stru;
int main()
{
stru *Memory = (stru*)malloc(sizeof(stru));
//Memory = NULL;
Memory->a=12;
Memory->b = 21;
free(Memory);
printf("%d ",Memory->b);
return 0;
}
Note: View last two lines. Memory freed . After that we are trying to get the value.
OutPut: Garbage value
Sunday, October 10, 2010
How to print the single linked list in reverse order without using array or memory?
/*
* list1.c
* Display the single linked list in reverse order
* Created on: Oct 11, 2010
* Author: Karthikeyan.D
*/
#include<stdio.h>
#include<conio.h>
#include<malloc.h>
typedef struct struNode
{
int nVal;
struct struNode *pstruNext;
}pstruStart;
int fnReversePrint(pstruStart* nTempLoation);
int fnReversePrint(pstruStart* nTempLoation)
{
if(nTempLoation->pstruNext != NULL)
{
fnReversePrint(nTempLoation->pstruNext);
printf("-->%d",nTempLoation->nVal);
}
else
{
printf("NULL-->%d",nTempLoation->nVal);
}
return 0;
}
int main()
{
struct struNode *pstruStart=NULL;
struct struNode *pstruNewnode,*pstruCurrent;
int nN;
int nI;
printf("enter the number of nodes\n");
scanf("%d",&nN);
for(nI=0;nI<nN;nI++)
{
pstruNewnode=(struct struNode*)malloc(sizeof(struct struNode));
printf("enter the data\n");
scanf("%d",&pstruNewnode->nVal);
pstruNewnode->pstruNext=NULL;
if(pstruStart==NULL)
{
pstruStart=pstruNewnode;
pstruCurrent=pstruNewnode;
}
else
{
pstruCurrent->pstruNext=pstruNewnode;
pstruCurrent=pstruNewnode;
}
}
printf("the linked list is\n");
pstruNewnode=pstruStart;
while(pstruNewnode!=NULL)
{
printf("%d----->",pstruNewnode->nVal);
pstruNewnode=pstruNewnode->pstruNext;
}
printf("NULL\n");
fnReversePrint(pstruStart);
return 0;
}
INPUT:
enter the number of nodes: 5
enter the data: 10
enter the data: 20
enter the data: 30
enter the data: 40
enter the data: 50
OUTPUT:
the linked list is
10----->20----->30----->40----->50----->NULL
NULL-->50-->40-->30-->20-->10
* list1.c
* Display the single linked list in reverse order
* Created on: Oct 11, 2010
* Author: Karthikeyan.D
*/
#include<stdio.h>
#include<conio.h>
#include<malloc.h>
typedef struct struNode
{
int nVal;
struct struNode *pstruNext;
}pstruStart;
int fnReversePrint(pstruStart* nTempLoation);
int fnReversePrint(pstruStart* nTempLoation)
{
if(nTempLoation->pstruNext != NULL)
{
fnReversePrint(nTempLoation->pstruNext);
printf("-->%d",nTempLoation->nVal);
}
else
{
printf("NULL-->%d",nTempLoation->nVal);
}
return 0;
}
int main()
{
struct struNode *pstruStart=NULL;
struct struNode *pstruNewnode,*pstruCurrent;
int nN;
int nI;
printf("enter the number of nodes\n");
scanf("%d",&nN);
for(nI=0;nI<nN;nI++)
{
pstruNewnode=(struct struNode*)malloc(sizeof(struct struNode));
printf("enter the data\n");
scanf("%d",&pstruNewnode->nVal);
pstruNewnode->pstruNext=NULL;
if(pstruStart==NULL)
{
pstruStart=pstruNewnode;
pstruCurrent=pstruNewnode;
}
else
{
pstruCurrent->pstruNext=pstruNewnode;
pstruCurrent=pstruNewnode;
}
}
printf("the linked list is\n");
pstruNewnode=pstruStart;
while(pstruNewnode!=NULL)
{
printf("%d----->",pstruNewnode->nVal);
pstruNewnode=pstruNewnode->pstruNext;
}
printf("NULL\n");
fnReversePrint(pstruStart);
return 0;
}
INPUT:
enter the number of nodes: 5
enter the data: 10
enter the data: 20
enter the data: 30
enter the data: 40
enter the data: 50
OUTPUT:
the linked list is
10----->20----->30----->40----->50----->NULL
NULL-->50-->40-->30-->20-->10
Sunday, October 3, 2010
Counting bits
/*
* To count the number bits used for the value representation.
*/
# include <stdio.h>
# include < stdlibb.h>
int bitcount(unsigned char x)
{ int count;
for (count=0; x != 0; x>>=1)
if ( x & 01) count++;
return count;
}
int main()
{
int BitCount;
BitCount = bitcount(10);
printf("Number of BitCount = %d\n ",BitCount);
return 0;
}
* To count the number bits used for the value representation.
*/
# include <stdio.h>
# include < stdlibb.h>
int bitcount(unsigned char x)
{ int count;
for (count=0; x != 0; x>>=1)
if ( x & 01) count++;
return count;
}
int main()
{
int BitCount;
BitCount = bitcount(10);
printf("Number of BitCount = %d\n ",BitCount);
return 0;
}
Timer Problem
/* timer.c */
/* Computes the time in seconds to do a computation */
#include <stdio.h>
#include <sys/types.h>
#include <time.h>
main()
{ int i;
time_t t1,t2;
(void) time(&t1);
for (i=1;i<=1000;++i)
printf(``%d %d %dn'',i, i*i, i*i*i);
(void) time(&t2);
printf(``n Time to do 1000 squares and
cubes= %d secondsn'', (int) t2-t1);
}
/* Computes the time in seconds to do a computation */
#include <stdio.h>
#include <sys/types.h>
#include <time.h>
main()
{ int i;
time_t t1,t2;
(void) time(&t1);
for (i=1;i<=1000;++i)
printf(``%d %d %dn'',i, i*i, i*i*i);
(void) time(&t2);
printf(``n Time to do 1000 squares and
cubes= %d secondsn'', (int) t2-t1);
}
Tuesday, September 28, 2010
Pointer Size in gcc Compiler
/*
* PointerSize.c
*
* Created on: Sep 29, 2010
* Author: Karthikeyan.D
*/
/* Size of any type of pointer is independent of the data
* type which is it is pointing i.e. size of pointer is always fixed.
* Size of any type (near) of pointer in c is four byte. (gcc Compiler)
*/
#include <stdio.h>
int main()
{
int *p1;
long double *p2;
printf("%d %d",sizeof(p1),sizeof(p2));
return 0;
}
OUTPUT:
4 4
* PointerSize.c
*
* Created on: Sep 29, 2010
* Author: Karthikeyan.D
*/
/* Size of any type of pointer is independent of the data
* type which is it is pointing i.e. size of pointer is always fixed.
* Size of any type (near) of pointer in c is four byte. (gcc Compiler)
*/
#include <stdio.h>
int main()
{
int *p1;
long double *p2;
printf("%d %d",sizeof(p1),sizeof(p2));
return 0;
}
OUTPUT:
4 4
Directory finding
/*
* Finding the files in the particular files.
*
*/
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
# include <string.h>
int isFileExist(char* dirName, char* fileName)
{
DIR *dp;
struct dirent *ep;
dp = opendir ("./");
if (dp != NULL)
{
while(ep = readdir(dp))
{
puts (ep->d_name);
if(strcmp(fileName, ep->d_name) ==0)
return 0;
}
(void) closedir (dp);
}
else
perror ("Couldn't open the directory");
return -1;
}
int main (void)
{
printf("is Exist %d",isFileExist("./","Printf.c"));
//perror("flfllfglllglf");
/* DIR *dp;
struct dirent *ep;
dp = opendir ("./");
if (dp != NULL)
{
while(ep = readdir(dp))
puts (ep->d_name);
(void) closedir (dp);
}
else
perror ("Couldn't open the directory"); */
return 0;
}
Sunday, September 26, 2010
Printf Concept
/*
* Printf.c
*printf return the number of characters which is to be displayed in the console window.
* Created on: Sep 26, 2010
* Author: Karthikeyan.D
*/
# include <stdio.h>
int main()
{
int nCount=0;
nCount = printf("Hello India\n");
printf("%d",nCount);
return 0;
}
OUTPUT:
Hello World
12
Note: \n consider as a escape sequence and also number of character count for this is only one. not two.
What is Data Abstraction?
Data Abstraction is a process of representing the essential features without including background or implementation level details.
Subscribe to:
Posts (Atom)