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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:18:57+00:00 2026-06-02T04:18:57+00:00

could you say me what is the mistake in my following code? char* line=;

  • 0

could you say me what is the mistake in my following code?

    char* line=""; 

printf("Write the line.\n");
scanf("%s",line);
printf(line,"\n");

I’m trying to get a line as an input from the console.But everytime while using “scanf” the program crashes. I don’t want to use any std, I totally want to avoid using cin or cout. I’m just trying to learn how to tak a full line as an input using scanf().

Thank you.

  • 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-02T04:18:59+00:00Added an answer on June 2, 2026 at 4:18 am

    You need to allocate the space for the input string as sscanf() cannot do that itself:

    char line[1024]; 
    
    printf("Write the line.\n");
    scanf("%s",line);
    printf(line,"\n");
    

    However this is dangerous as it’s possible to overflow the buffer and is therefore a security concern. Use std::string instead:

    std::string line;
    
    std::cout << "Write the line." << std::endl;
    std::cin >> line;
    std::cout << line << std::endl;
    

    or:

    std::getline (std::cin, line);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have the following three strings: (section1){stuff could be any character, i
Probably a conceptual mistake from my part but let's say I have a function
I was following example from microsoft site for reading from text file. They say
For instance, the app could say something like, Please wait. or I'll be right
say I have a string like so Testing How could I have it remove
Say I am required to build an E-Commerce website that could eventually become very
Say there is: class A(B): ... where B could be object and ... is
Say I've got an app with a laughably awful GUI setup screen. I could
Say this is my string $string = 'product[0][1][0]'; How could I use that string
How could I adapt this query to show the previous, say, 61 weeks? select

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.