starun8795's blog

By starun8795, history, 7 years ago, In English
#include<iostream>
#include<cstdio>
using namespace std;

int main()
{
	int n,m;
	scanf("%d%d", &n, &m);
	const int max=1005;
	char t1[max], t2[max];
	gets(t1);
	gets(t2);
	printf("%s\n%s", t1, t2);
	return 0;
}

Or you can also see the code link on ideone

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
7 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by starun8795 (previous revision, new revision, compare).

  • »
    »
    7 years ago, # ^ |
    Rev. 3   Vote: I like it +1 Vote: I do not like it

    When you input an option with the scanf() call, you type 3 keys on your keyboard, for example, 3, 4 and ENTER.

    The scanf() consumes the '3' but leaves the ENTER hanging in the input buffer.

    When, later, you do gets() that ENTER is still in the input buffer and that's what gets() gets.

    You have two options:

    clear the input buffer after each scanf() clear the input buffer before each gets() To clear the input buffer use this code:

    int clear_input_buffer(void) { int ch; while (((ch = getchar()) != EOF) && (ch != '\n')) /* void */; return ch; } Oh! And stop using gets(). gets() is impossible to use safely. Use fgets() instead.

    also you can see this link

»
7 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

I think it doesn't read strings correctly because you read ints n and m before them and program read empty string till end of line(\n).

First string is empty

You can fix it with a space in the end of ints' scanf

That way

(sry 4 bed inglish)