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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:47:06+00:00 2026-06-03T22:47:06+00:00

I am working on a program that includes a selection of code which is

  • 0

I am working on a program that includes a selection of code which is “supposed” to filter a string in order to prevent non-alphanumeric characters (except for underscores) from being passed further on into the program. The part that does this worked fine when I tested it before implementing it in the main program (as shown below), but when I run it now the output is just repeated a bunch of times until there is a segmentation fault, and i cannot for the life of me figure out what is causing this to happen, so if anyone could help with this problem I would very much appreciate it, thanks! also for ease of seeing where this is implemented in the main program, i have taken a screenshot of where it is located in the main code https://i.stack.imgur.com/uzodA.png, and my apologies for the long post length

austin@Ruby:~/cprac$ ./words
[hel123_lo]

testing code that worked

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

int main(void) {
    int i;
    char *p;
    char stg[] = "hel123*^_l!o";
    char output[200] = {0x00};
    int index = 0;


    p = stg;
    while( *p )
    {
    if (isalnum(*p) || *p == '_')
    {
        output[index++] = *p;
    }
    p++;
    }

printf("[%s]\n", output);
return 0;
}

main code

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

#ifndef max
#define max(a, b) ((a)>(b))? (a) : (b)
#endif

long GetFileSize(FILE *fp){
long fsize = 0;

fseek(fp,0,SEEK_END);
fsize = ftell(fp);
fseek(fp,0,SEEK_SET);//reset stream position!!

return fsize;
}
char *lastline(char *filepath){
FILE *fp;
char buff[4096+1];
int size,i;
long fsize;
if(NULL==(fp=fopen(filepath, "r"))){
    perror("file cannot open at lastline");
    return NULL;
}
fsize= -1L*GetFileSize(fp);
if(size=fseek(fp, max(fsize, -4096L), SEEK_END)){
    perror("cannot seek");
    exit(0);
}
size=fread(buff, sizeof(char), 4096, fp);
fclose(fp);
buff[size] = '\0';
i=size-1;
if(buff[i]=='\n'){
    buff[i] = '\0';
}
while(i >=0 && buff[i] != '\n')
    --i;
++i;
return strdup(&buff[i]);
}

int main(int argc, char *argv[], char *envp[]){
    char *last;
    char *name;
    char field_x[128];
    char field_y[128];
    char field_z[128];
    char field_world[128];
    char field_cause[128];
    char field_killer[128];
    name = getenv("MCEXEC_PLAYERNAME");
    char *filename;
    char *p;
    char *ispvp;
    // m
    int i;
    char *f;
    char output[200] = {0x00};
    int index = 0;
    filename = malloc(sizeof "/home/minecraft/freedonia/playerdata/deathlog-.txt" - 1 +     strlen(name) + 1);
    if (!filename) exit(EXIT_FAILURE);
    snprintf(filename,4096,"/home/minecraft/freedonia/playerdata/deathlog-  %s.txt",name);
    last = lastline(filename);
    if( last != NULL ) {
    printf( "%s\n", last );
    sscanf(last, "%*[^:]:%*[^:]:%*[^:]:%127[^:]:", field_x);
    sscanf(last, "%*[^:]:%*[^:]:%*[^:]:%*[^:]:%127[^:]:", field_y);
    sscanf(last, "%*[^:]:%*[^:]:%*[^:]:%*[^:]:%*[^:]:%127[^:]:", field_z);
    sscanf(last, "%*[^:]:%*[^:]:%*[^:]:%*[^:]:%*[^:]:%*[^:]:%127[^:]:", field_world);
    sscanf(last, "%*[^:]:%*[^:]:%*[^:]:%*[^:]:%*[^:]:%*[^:]:%*[^:]:%127[^:]:", field_cause);
    p = strchr(field_cause, '_');
    printf( "X coord: %s\n", field_x);
    printf( "Y coord: %s\n", field_y);
    printf( "Z coord: %s\n", field_z);
    printf( "World: %s\n", field_world);
    printf( "Cause: %s\n", field_cause);
    while (p != NULL) {
    ispvp = "true";
   // printf ("found at %d\n",p - field_cause + 1);
    sscanf(field_cause, "%*[^_]_%128[^_]_", field_killer);
    printf( "%s\n", field_killer);
    f = field_cause;
    while( *f )
    {
      if (isalnum(*f) || *f == '_')
      {
        output[index++] = *f;
      }
      f++;
    }

    printf("[%s]\n", output);
 //   p = strchr(p + 1, '_');
    }

    }
//    printf("\"%s\"\n", last);
free(last);
return 0;
}
  • 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-03T22:47:08+00:00Added an answer on June 3, 2026 at 10:47 pm
        while (p != NULL) {
        ispvp = "true";
        // printf ("found at %d\n",p - field_cause + 1);
        sscanf(field_cause, "%*[^_]_%128[^_]_", field_killer);
        printf( "%s\n", field_killer);
        f = field_cause;
        while( *f )
        {
          if (isalnum(*f) || *f == '_')
          {
            output[index++] = *f;
          }
          f++;
        }
    
        printf("[%s]\n", output);
        //   p = strchr(p + 1, '_');
        }
    

    P never changes in this block, so it will always be != NULL.

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

Sidebar

Related Questions

I'm working on a program that reads in users input as a string, which
I'm working on a clojure program that includes these lines of code: (defn makeStruct
I am working on a program which includes a general purpose engine, some program
I'm working on a program that needs a feature that has similar functionality as
I am working on a program that needs to create a multiple temporary folders
I'm working on a program that processes many requests, none of them reaching more
I'm working on a program that searches entire drives for a given file. At
I'm working on a program that uses PHP's internal array pointers to iterate along
I'm working on a program that will sort files based on extension I currently
I'm working on a program that asks for input, then calculates and posts the

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.