You are not logged in. Please login at www.codechef.com to post your questions!

×

how to take a string with white spaces in c???

how to take a string input with white spaces in c???

asked 07 Jul '17, 23:28

parth191's gravatar image

1★parth191
7061316
accept rate: 4%


You could use :

scanf("%[^\n]s", string);

This will get a string till a new line is encountered. Or you could instead use

fgets(string, len, stdin)

Here len is the number of characters you want to read. However using fgets will also store a new line character at the end!

link

answered 07 Jul '17, 23:40

captaindavinci's gravatar image

4★captaindavinci
363
accept rate: 33%

You can use gets() function.
It can receive a multi-word string.

gets example

#include <stdio.h>

int main()
{
  char string [256];
  printf ("Insert your full address: ");
  gets (string);
  printf ("Your address is: %s\n",string);
  return 0;
}
link

answered 07 Jul '17, 23:44

pankaj_chopra's gravatar image

3★pankaj_chopra
32929
accept rate: 21%

edited 08 Jul '17, 00:06

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,477
×643
×169

question asked: 07 Jul '17, 23:28

question was seen: 1,732 times

last updated: 08 Jul '17, 00:06