hmtech505's blog

By hmtech505, history, 9 years ago, In English

Fill block of memory Sets the first num bytes of the block of memory pointed by ptr to the specified value (interpreted as an unsigned char)

Parameters ptr

Pointer to the block of memory to fill. value Value to be set. The value is passed as an int, but the function fills the block of memory using the unsigned char conversion of this value.
num Number of bytes to be set to the value.

/* memset example */

include <stdio.h>

include <string.h>

int main ()

{

char str[] = "you damn!";

memset (str,'-',6);

puts (str);

return 0;

}

Output:

------ you damn!

Full text and comments »

  • Vote: I like it
  • -21
  • Vote: I do not like it

By hmtech505, history, 9 years ago, In English

ObjectInputStream Example

Here is a Java ObjectInputStream example:

ObjectInputStream objectInputStream =
    new ObjectInputStream(new FileInputStream("object.data"));

MyClass object = (MyClass) objectInputStream.readObject();
//etc.

objectInputStream.close();

For this ObjectInputStream example to work the object you read must be an instance of MyClass, and must have been serialized into the file "object.data" via an ObjectOutputStream.

Before you can serialize and de-serialize objects the class of the object must implement java.io.Serializable. For more info, see Java Serializable.

Full text and comments »

  • Vote: I like it
  • -3
  • Vote: I do not like it