Baekjun Algorithm #11719

Asked 2 years ago, Updated 2 years ago, 26 views

Input is given. The input consists of up to 100 lines, only lowercase letters, uppercase letters, spaces, and numbers. Each line may not exceed 100 characters, may be given an empty line, or may have a space before and after each line.

Enter

   Hello

Baekjoon  
   Online Judge 
Output
   Hello

Baekjoon  
   Online Judge 

I'm trying to solve this problem, but it's not working out ㅠ<

//#include <stdio.h>
#include <string.h>

int main() {
  char str[100];

  while(scanf("%[^\n]s", str) != -1){
    printf("%s\n", str);
  }
  return 0;

}

If you do this, you can print out all the other lines I can't print out empty spaces How should I solve it? Help me!

c

2022-09-22 12:36

1 Answers

#include <stdio.h>

int main(void)
{
  char str[128] = {0};
  while(fgets(str, 128, stdin) != NULL)
    printf("%s", str);

  return 0;
}

or

#include <stdio.h>

int main(void)
{
    char a = getchar();
    while(a != EOF)
    {
        printf("%c", a);
        a = getchar();
    }

    return 0;
}

There's this solution.


2022-09-22 12:36

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.