seekg(), tellg()

seekg()
Set position of the get pointer
Sets the position of the get pointer.
The get pointer determines the next location to be read in the source associated to the stream.

tellg()
Get position of the get pointer.
Returns the absolute position of the get pointer.
The get pointer determines the next location in the input sequence to be read by the next input operation.

[Example]
// read a file into memory
#include
#include
using namespace std;

int main () {
int length;
char * buffer;

ifstream is;
is.open (“test.txt”, ios::binary );

// get length of file:
is.seekg (0, ios::end);
length = is.tellg();
is.seekg (0, ios::beg);

// allocate memory:
buffer = new char [length];

// read data as a block:
is.read (buffer,length);

is.close();

cout.write (buffer,length);

return 0;
}

Posted in open-source | Leave a comment

What is difference between static and extern?

int varA ; // has external linkage (global), and static storage class
static int varB ; // has static linkage (module local), and static storage class

void funcA()
{
static varC ; // has static storage class and local scope
}

extern int varA ; // declaration without instantiation

Posted in open-source | Leave a comment

Using a Function Pointer

To call the function pointed to by a function pointer, you treat the function pointer as though it were the name of the function you wish to call. The act of calling it performs the dereference; there’s no need to do it yourself:

#include
void my_int_func(int x)
{
printf( “%d\n”, x );
}

int main()
{
void (*foo)(int);
foo = &my_int_func;

/* call my_int_func (note that you do not need to write (*foo)(2) ) */
foo( 2 );
/* but if you want to, you may */
(*foo)( 2 );

return 0;
}

Posted in open-source | Leave a comment

malloc()

malloc() should be used with free()

Syntax:
#include
Description:
The function malloc() returns a pointer to a chunk of memory of size size, or NULL if there is an error. The memory pointed to will be on the heap, not the stack, so make sure to free it when you are done with it.

Example:
typedef struct data_type {
int age;
char name[20];
} data;

data *bob;
bob = (data*) malloc( sizeof(data) );
if( bob != NULL ) {
bob->age = 22;
strcpy( bob->name, “Robert” );
printf( “%s is %d years old\n”, bob->name, bob->age );
}
free( bob );

Posted in open-source | Leave a comment

Void Pointer

There are some examples in below

It will help you to understand how void pointer works

void use_int(void *r) {
int a;
a = * (int *) r;
printf(“As an integer, you are %d years old.\n”, a);
}

void use_float(void *s) {
float *b;
b = (float *) s;
printf(“As a float, you are %f years old.\n”, *b);
}

Posted in open-source | Leave a comment

Rules&Tips for IRC

[Rules]

1. Casual chatting on IRC

2. If you need to pass a url to others in a meeting, don’t use a long url

3. Do not copy and paste code in a char room

[Tips]

/join #channel_name (Join #channel)

/nick nickname (Change your nickname)

/query nickname (Open a private chat with some one)

/me [messages] (/me represents nickname)

Posted in open-source | Leave a comment

printf() function return vlaue

printf() retuns number of characters

e.g. int a = 10;

printf(“%d”, printf(“%d %d %d\n”, a, a, a));

Total 9 characters get printed include ‘\n’

Posted in open-source | Leave a comment

Hello world!

Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!

Posted in Uncategorized | 1 Comment