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

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.