Lim Ewe Win Lim Ewe Win - 2 months ago 6
C Question

Printf additional newline with inserting a string value in printf

printf("It is currently %s's turn.\n", current->name);

Hi, guys. I currently new to C programming and I was wondering why is this printing out additional newline after the %s. I am aware that strings in C always ends with \0. How to I print it out without it?


Your variable current->name has a newline in it, so you need to get rid of that newline.

current->name[strcspn(current->name, "\n")] = '\0';

This piece of code will help you get rid of the unwanted newline. Put it before printf.