Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7914809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:14:34+00:00 2026-06-03T14:14:34+00:00

i am currently rewriting a log parsing script from bash into C, and i

  • 0

i am currently rewriting a log parsing script from bash into C, and i was just wondering if i could get some advice regarding how i can set the array called buffer to expand dynamically instead of being limited to 1024, I think i would use malloc, but im not too sure how to properly implement it for this specific application, any help is greatly appreciated, thanks!

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _GNU_SOURCE
void main(int argc, char *argv[], char *envp[])
{
  FILE *fd;
  char *name;
  name = getenv("MCEXEC_PLAYERNAME");
  char *filename;
  filename = malloc(sizeof "/home/minecraft/freedonia/playerdata/deathlog-.txt" - 1 +    strlen(name) + 1);
  if (!filename) exit(EXIT_FAILURE);
  sprintf(filename,"/home/minecraft/freedonia/playerdata/deathlog-%s.txt",name);
  char buff[1024];
  if ((fd = fopen(filename, "r")) != NULL)
  {
    fseek(fd, 0, SEEK_SET);

    while(!feof(fd))
    {
      memset(buff, 0x00, 1024);
      fscanf(fd, "%[^\n]\n", buff);
    }
    printf("%s\n", buff);
  }
  else
  printf( "fail" );
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T14:14:35+00:00Added an answer on June 3, 2026 at 2:14 pm

    Use malloc to allocate the array dynamically.

    If needed, realloc it to alter its size.

    EDIT:

    Instead of: char buff[1024];

    use:

    char *buff;
    buff = malloc(1024); //This will allocate 1024 chars
    

    You can use another variable like: char tmp[256]; to read from file and store it into buff. As you put tmp into buff, keep note of the size of chars in buff. If necessary, make a call to realloc:

    len = sizeof(buff);
    buff = realloc(buff, len+256); //This will increase the buff size by 256
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently rewriting some existing technologies that were once using RSA Security's libraries into
I'm using Intelligencia url rewriting currently but have just leased an IIS 7.5 server
I'm currently rewriting urls from http://domain.com/profile/?u=10000017564881 this to this http://domain.com/profile/10000017564881 with the following rewrite
I am currently rewriting a small project i written some time ago, and am
I'm currently busy with rewriting an application into MVVM (in stages, because it is
I'm currently rewriting some python code to make it more efficient and I have
Currently I'm rewriting some old C++ code to C#. When running some tests it
I'm currently in the process of messing about with Magento, and I'm just wondering
I'm currently rewriting a free educational digital circuit simulator to add inertiality to its
I'm currently rewriting an e-shop - but only the client side, i.e. the CMS

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.