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

The Archive Base Latest Questions

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

I am currently working on a log parsing script for a server, and to

  • 0

I am currently working on a log parsing script for a server, and to prevent users from inputting malicious commands, I need to filter out all characters except for alphanumeric characters (while allowing underscores) from the inputted string, although unfortunately I do not know how to do this, so I was just wondering if someone could tell/show me what to do in order to achieve this, thanks! also as an example, say someone inputs the following: stack#@_over%flow, the program would then filter out the non-alphanumeric characters (except for underscores) in order to produce just stack_overflow, the equivalent of this in bash would be

tr -dc [:alnum:]'_'

also forgot to mention that I have tried the following, but still encounter some issues (for instance if a “!” is included in the string, i get “-bash: !”: event not found”

#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(int argc, char ** argv) {
    int i;
    char *p;
    if (argc > 1) {
        for (p = argv[1]; *p != '\0'; p++) {
           if (islower(*p) || isdigit(*p) || *p == '_') {
               putchar (*p);
           }
        }
        putchar ('\n');
    }
    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-03T15:13:47+00:00Added an answer on June 3, 2026 at 3:13 pm

    Find the length of the string you are processing, allocate a new string of that length, iterate over every character of the input string and if it is alpha numeric (using isalnum() from ctype.h) put the character in the resulting string, else just skip it. Null terminate and copy the resulting string to the input string, free the allocated string and return the result.

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

Sidebar

Related Questions

I'm currently working on an SSIS package to load mainframe logs from multiple server/file
I'm currently working on a parser for our internal log files (generated by log4php,
Currently working on a script to ping every host on a /24 subnet, and
Am currently working on an application that requires users to submit posts and comments
I`m currently working out the design for simple graphic editor, who support trivial operations
I am currently working on a Log in form but the thing here is
I am currently working on a log in form and I've heard the best
I am currently working on an iPhone app that will have a user log
I'm currently working on a logging solution for one of our web projects. Server
I am currently working on a call log project. The boss wants me to

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.