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

📄 realloc.c

📁 c21Examples.rar
💻 C
字号:
/* Using realloc() to change memory allocation. */

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

int main( void )
{
    char buf[80], *message;

    /* Input a string. */

    puts("Enter a line of text.");
    gets(buf);

    /* Allocate the initial block and copy the string to it. */

    message = realloc(NULL, strlen(buf)+1);
    strcpy(message, buf);

    /* Display the message. */

    puts(message);

    /* Get another string from the user. */

    puts("Enter another line of text.");
    gets(buf);

    /* Increase the allocation, then concatenate the string to it. */

    message = realloc(message,(strlen(message) + strlen(buf)+1));
    strcat(message, buf);

    /* Display the new message. */
    puts(message);
    return 0;
}

⌨️ 快捷键说明

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