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 7898935
In Process

The Archive Base Latest Questions

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

I am working on a log parsing program that retrieves the file to open

  • 0

I am working on a log parsing program that retrieves the file to open by combining an environment variable and a preset string in order to provide the full path to the file, but i am having trouble getting fopen to take out the output from sprintf which i am using to combine the environment variable and the preset string,so i was wondering if anyone could offer advice on what i should do to get this to work properly? thanks! (i have just begun teaching myself C over the last few weeks, so im open to any tips no matter how obvious they should be to me)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _GNU_SOURCE
void main(int argc, char *argv[], char *envp[])
{
  FILE *fd; // File pointer
  char *name;
  char *filename[];
  name = getenv("MCEXEC_PLAYERNAME");
  sprintf(filename,"/home/minecraft/freedonia/playerdata/deathlog-%s.txt",name);
  char buff[1024];
  if ((fd = fopen(filename, "r")) != NULL) // open file
  {
    fseek(fd, 0, SEEK_SET); // make sure start from 0

    while(!feof(fd))
    {
      memset(buff, 0x00, 1024); // clean buffer
      fscanf(fd, "%[^\n]\n", buff); // read file *prefer using fscanf
    }
    printf("Last Line :: %s\n", buff);
  }
  else
  printf( "fail" );
}

here is the error i get while compiling using gcc

lastline.c: In function ‘main’:
lastline.c:9: error: array size missing in ‘filename’
lastline.c:11: warning: passing argument 1 of ‘sprintf’ from incompatible pointer type
/usr/include/stdio.h:341: note: expected ‘char * __restrict__’ but argument is of type   ‘char **’
lastline.c:13: warning: passing argument 1 of ‘fopen’ from incompatible pointer type
/usr/include/stdio.h:249: note: expected ‘const char * __restrict__’ but argument is of   type ‘char **’
  • 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-03T08:34:14+00:00Added an answer on June 3, 2026 at 8:34 am
    char *filename[];
    

    declares an array of pointers to char of unknown size. You need an array of char to sprintf to, of sufficient known length. Declare

    char filename[1000];  // assuming 1000 is large enough
    

    or

    char *filename;
    

    as a pointer to char and malloc sufficient memory after you have gotten the name,

    filename = malloc(sizeof "/home/minecraft/freedonia/playerdata/deathlog-.txt" - 1 + strlen(name) + 1);
    if (!filename) exit(EXIT_FAILURE);
    

    to avoid unpleasant surprises if name turns out longer than expected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working with a log file and I have a method which is
Working on a project that parses a log of events, and then updates a
I am working on an Audit Log for an application that uses Linq-To-Sql. I
I'm working on implementing a log based file system for a file as a
I'm working with an application that logs to Windows Application Log regularly (viewable through
I am working on a log parsing script using Perl. I am reading the
I'm working on a small app that uses and xml file to print an
I am currently working on a log parsing script for a server, and to
We're working on a Log Viewer. The use will have the option to filter
I am working with a log of events where there are about 60 different

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.