0

I use scanf("%[^\n]%*c", s) statement to get string, but what is the proper indentation to print this string?

I am a beginner and overall confused with string input-output instructions. Some tips on this topic would be helpful...!

General Grievance
  • 4,555
  • 31
  • 31
  • 45
  • 1
    Welcome to Stack Overflow. Please read [the help pages](http://stackoverflow.com/help), take the SO [tour], read [ask], as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). Lastly please learn how to create a [mcve] and how to [edit] your question to show it (and to put the actual question inside the question body, and edit the title to be a short summary). – Some programmer dude Jul 12 '21 at 13:03
  • The way you print a string is independent of the way you get it from user. Use something like `printf("%s\n", s);` to print the string and the a new line. – fpiette Jul 12 '21 at 13:10
  • 1
    What do you mean by "proper" identation? You can print it anyway you like – Support Ukraine Jul 12 '21 at 13:11
  • 2
    Please don't take this as an insult, but if you are a beginner, string input in C is always going to be a little bit confusing. Please don't even try to use `%[^\n]` or `%*c`. They're not worth it, and no one should have suggested them to you. Please just use `%s` at first. It's not perfect, but when you're ready to learn about its shortcomings and move on to something better, the "something better" to move on to is [`fgets`](https://stackoverflow.com/questions/58403537), not anything involving fancy `scanf` format strings.. – Steve Summit Jul 12 '21 at 13:15
  • Please provide a [mre] which demonstrates what you have achieved yourself. Then desribe what is unsatisfying about the result you get. Also, have a look at http://sekrit.de/webdocs/c/beginners-guide-away-from-scanf.html I do not really want to contradict Steve Summit, but please understand that using `"%s"` is dangerous in the presence of bad luck or malicious users. – Yunnosch Jul 12 '21 at 13:23
  • Prathamesh Kakde: "what is the proper indentation to print this string?" --> Try `printf("%s", s);` – chux - Reinstate Monica Jul 12 '21 at 13:34

0 Answers0