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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:50:01+00:00 2026-06-02T00:50:01+00:00

If I was to let a user input a filename for a file (allowing

  • 0

If I was to let a user input a filename for a file (allowing spaces) and validate it to see if it is a bad file name, how would I do so?

The only way right now that I can think of is to create char array like

char filename[100]

And use a for loop and have nested if statements that checks if each single character of the strings are !@%^*~| and etc by writings lines like these

for(...) {
    if(filename[i] == '@'){...}
    if(filename[i] == '!'){...}
}

Are there better ways to approach this? Because if I was to doing it like that, I would have A LOT of individual if statements just to test all the possible illegal characters.

  • 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-02T00:50:03+00:00Added an answer on June 2, 2026 at 12:50 am

    You can use strchr for that, and if the return is not null, you have found a bad character.

    char bad_chars[] = "!@%^*~|";
    char invalid_found = FALSE;
    int i;
    for (i = 0; i < strlen(bad_chars); ++i) {
        if (strchr(filename, bad_chars[i]) != NULL) {
            invalid_found = TRUE;
            break;
        }
    }
    if (invalid_found) {
        printf("Invalid file name");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does Octave have a good way to let the user select an input file?
i want to let the user type in the name of a new file,
I have a program written in C using ncurses. It let user input and
Is there any way to let user pick color from screen ? Like the
So I have a file for constants. I want to let user define them
I wrote a simple web app to let user input data as they walk
Let's say I have some form where user input some WCF/RIA Services URL and
I want to create textfields based on user input. Let's say 5 textfield are
Let's say I have an input text file of the following format: Section1 Heading
Let's assume I create the following two strings at runtime (from user input for

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.