⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 memalloc.c

📁 里面包含很多c语言的源码
💻 C
字号:
/* Demonstrates the use of malloc() to allocate storage */
/* space for string data. */

#include <stdio.h>
#include <stdlib.h>

char count, *ptr, *p;

int main( void )
{
   /* Allocate a block of 35 bytes. Test for success. */
   /* The exit() library function terminates the program. */

   ptr = malloc(35 * sizeof(char));

   if (ptr == NULL)
   {
       puts("Memory allocation error.");
       return 1;
   }

   /* Fill the string with values 65 through 90, */
   /* which are the ASCII codes for A-Z. */

   /* p is a pointer used to step through the string. */
   /* You want ptr to remain pointed at the start */
   /* of the string. */

   p = ptr;

   for (count = 65; count < 91 ; count++)
       *p++ = count;

   /* Add the terminating null character. */

   *p = '\0';

   /* Display the string on the screen. */

   puts(ptr);

   free(ptr);

   return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -