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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:53:43+00:00 2026-06-09T00:53:43+00:00

I wrote a little piece of code that would input address from the keyboard.

  • 0

I wrote a little piece of code that would input address from the keyboard. However, I am not able to figure out how may I be able to read in special characters, such as hypen, colon etc. Can you please suggest some edit to my code below:

#include<stdio.h>

main()
{
       char address[80];


       printf("Enter address: ");
       scanf("%[a-z | A-Z | 0-9]", address); //How may I include characters like hypen.
       printf("\n\n%s\n\n", address);
}

Output that I am getting:

Enter Address: Plot No - 16, Palm Grooves, Nagpur - 440022, India

Plot No

No commas, no hyphen, no numeral is being displayed.

Thank you for your help and comments.

  • 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-09T00:53:44+00:00Added an answer on June 9, 2026 at 12:53 am

    Add them to the list of acceptable characters one by one, like this:

    "%[a-z | A-Z | 0-9/,.-]"
    

    Here is this example on ideone.

    Since you are using scanf into a buffer of limited size, it is a good idea to add a size constraint to the format specifier in order to avoid buffer overruns:

    char address[81]; // One extra character for padding
    printf("Enter address: ");
    scanf("%80[a-z | A-Z | 0-9/,.-]", address); // %80 limits the input
    printf("\n\n%s\n\n", address);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a little piece of code to expose my problem. public class date
I have a very simple little piece of Lua code, which I wrote while
I have a little piece of a library that I would like to write
Here's a little piece of code I wrote to report variables with missing values
I'm trying to compile this little piece of code from the boost documentation: (http://www.boost.org/doc/libs/1_46_1/libs/iostreams/doc/tutorial/filter_usage.html)
Some time ago I wrote a little piece of code to ask about on
I am very new to classic ASP. I wrote a little piece of code
I'm trying to write out a piece of code that can reduce the LENGTH
i wrote a little piece of code to determine, how memory allocating in a
I wrote a little script that exports certain Excel cell values into Word. However,

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.