1

I've a problem and I couldn't find answer.

I need to get 2 strings from user using scanf(must) and print them.

I have 2 problems 1. when I type the first string it's somehow skip the second one. 2. if my string includes spaces, I takes only the chars till the space, from what I think the 2nd word goes to the second "scanf"

this is my code

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
void main()
{
    char format[30];
    char numbers[20];

    scanf("%s", format);

    scanf("%s", numbers);

    printf("\n %s %s", format, numbers);
}

is it possible to get 2 strings from user 1 after another including spaces? Thanks in advance

Brec
  • 87
  • 1
  • 1
  • 8
  • Have a look at [this answer](http://stackoverflow.com/a/1247993/3657941). –  Nov 17 '16 at 19:21
  • I managed to scan the string with spaces but it's still skipping the second scanf – Brec Nov 17 '16 at 19:23

1 Answers1

0

I solved it this way

I added another scanf which I don't need and now skipping the second scanf but it stops on the third. not the best way but it helps.

scanf("%[^\n]s", format);
scanf("%c", &temp);
scanf("%[^\n]s", numbers);
Brec
  • 87
  • 1
  • 1
  • 8