Memset

Memset

memset

memset — функция стандартной библиотеки языка C, для заполнения буфера указанным символом.

Функция

Прототип, описанный в заголовочном файле memory.h и string.h.

void *memset( void *dest, int c, size_t count );

  • dest — указатель на буфер.
  • c — символ заполнения.
  • count — количество символов.

Пример использования

#include "stdafx.h"
#include "string.h"
#include "stdio.h"
#include "iostream"
#include "conio.h"
using namespace std;
struct MyStruct
{
	char test[4];
	int i;
};
 
void main()
{
	char buffer[10];
	strcpy(buffer,"123456789");
	cout << buffer << " not memcpy" << endl;
	memset(&buffer,'1',(sizeof(buffer)-1));
	cout << buffer << " yes memset" << endl;
        _getch();
}

Так же эту функцию можно применять для обнуления структур:

#include "stdafx.h"
#include "string.h"
#include "stdio.h"
#include "iostream"
#include "conio.h"
using namespace std;
 
struct MyStruct
{
	char test[5];
	int i;
};
 
void main()
{
	MyStruct mm;
	strcpy(mm.test,"hello");
	mm.i=5;
	cout << mm.i << " " <<  mm.test << " not memset " << endl;
	memset(&mm,0,sizeof(mm));
   	cout <<  mm.i << " " <<  mm.test << "      yes memset " << endl;
        _getch();
}

Wikimedia Foundation. 2010.

Игры ⚽ Нужен реферат?

Полезное


Смотреть что такое "Memset" в других словарях:

  • Kate Craig-Wood — (born 1977) is a British IT entrepreneur; the co founder and managing director of Memset Dedicated Hosting. She is also a champion for the causes of energy efficiency, especially in the data centre, and women in IT… …   Wikipedia

  • Berkeley sockets — The Berkeley sockets application programming interface (API) comprises a library for developing applications in the C programming language that perform inter process communication, most commonly across a computer network.Berkeley sockets (also… …   Wikipedia

  • Name mangling — This article is about name mangling in computer languages. For name mangling in file systems, see filename mangling. In compiler construction, name mangling (also called name decoration) is a technique used to solve various problems caused by the …   Wikipedia

  • Сокеты Беркли — Сокеты Беркли  интерфейс программирования приложений (API), представляющий собой библиотеку для разработки приложений на языке Си с поддержкой межпроцессного взаимодействия (IPC), часто применяемый в компьютерных сетях. Сокеты Беркли (также… …   Википедия

  • Example Pictor Decoder — Pictor PCPaint PIC image format PICtor is an image file format developed by John Bridges, the principal author of PCPaint, the first Paintbrush program for the PC. It was also the native file format for Pictor Paint and GRASP (multimedia… …   Wikipedia

  • Магическое число (программирование) — У этого термина существуют и другие значения, см. Магическое число. Понятие «Магическое число» в программировании имеет два значения: первое второе Содержание 1 Сигнатура данных 2 Плохая практик …   Википедия

  • Волшебное число — Понятие «Магическое число» в программировании имеет два значения: Содержание 1 Сигнатура данных 2 Плохая практика программирования …   Википедия

  • Магическое число (компьютер) — Понятие «Магическое число» в программировании имеет два значения: Содержание 1 Сигнатура данных 2 Плохая практика программирования …   Википедия

  • Defensive programming — is a form of defensive design intended to ensure the continuing function of a piece of software in spite of unforeseeable usage of said software. The idea can be viewed as reducing or eliminating the prospect of Murphy s Law having effect.… …   Wikipedia

  • Off-by-one error — An off by one error (OBOE) is a logical error involving the discrete equivalent of a boundary condition. It often occurs in computer programming when an iterative loop iterates one time too many or too few. Usually this problem arises when a… …   Wikipedia


Поделиться ссылкой на выделенное

Прямая ссылка:
Нажмите правой клавишей мыши и выберите «Копировать ссылку»