Ganesh Kathiresan
Ganesh Kathiresan

Reputation: 2088

Entering no character for input in C

Is there a way for the user to enter nothing as input(for character array) in C? I tried the following:

  1. Using a '\n' character as delimiter: scanf("%[^\n]s",str); it gave me junk.
  2. Used a custom delimiter like ' ` '. But additional task was required as in case if it was entered in between, etc.
  3. Tried using command line arguments for input string (as we know no input gives One argument expected)
  4. Tried entering null by alt+space. Did not work either.

Please suggest me a new way or correct me if I am doing any of the above steps wrong. Note: I am using Windows.

Upvotes: 1

Views: 348

Answers (1)

chqrlie
chqrlie

Reputation: 144550

If you take your input from command line arguments, you can specify an empty string with:

C:\>myprogram ""

argc will be 2 and argv[1] will be a pointer to an empty string.

Upvotes: 3

Related Questions