-2

I want to display fgets() input on 1 line, here the code:

printf("%s study at %s and he is %i years old", siswa01.name, siswa01.school, siswa01.age);

When I run the program, the output was like this:

jordan                                                                                                                   study at Las Vegas                                                                                                      and he is 12 years old

I want to display the output:

jordan study at las vegas and he is 12 years old

How can I get the display on 1 line using fgets()?

  • 1
    siswa01's class appears to change the school to capital letters, but it's hard to tell because you haven't provided enough source – Jon Doe Oct 20 '19 at 03:09
  • When I went to better format your question, I discovered that there are a LOT of spaces in the actual output part (you have "jordan" followed by 115 spaces followed by "study at Las Vegas" followed by 102 spaces, followed by "and he is 12 years old"). Is that accurate? Or did you insert the spaces in a futile attempt to make it appear that the output occupied multiple lines? (If you have trouble with the formatting, just do a strict copy-and-paste and ask for formatting help.) – JaMiT Oct 20 '19 at 03:18
  • Possible duplicate of [How do I trim leading/trailing whitespace in a standard way?](https://stackoverflow.com/questions/122616/how-do-i-trim-leading-trailing-whitespace-in-a-standard-way) – Mark Plotnick Oct 20 '19 at 04:44

1 Answers1

0

It looks like your siswa01.name variable does not contain jordan\0, but jordan ... \0, with some hundred blanks between the n and the end of the string.
As a result you get it printed with all those blanks.

The issue is in the code that fills that variable - which you didn't show, so we can't tell you what's wrong with it.

Aganju
  • 6,295
  • 1
  • 12
  • 23