I have created a little script in C which displays text in a Linux console, but I found one problem - the script adds a line break at the end of text. I have no idea why, normally I should get line break after /n
.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char buf[1024];
char txt[100];
printf("Insert a text: ");
fgets(txt, 100, stdin);
snprintf(buf, sizeof(buf), "echo '%s'", txt);
system(buf);
}
The structure of the code has to stay the same. I need to use system function and snprintf()
.
I want to make a few things clear. Right when I'm running this script the output looks like this:
root@test:/home# ./app
Insert a text: Hello
Hello
root@test:/home#
How can I remove this newline after Hello
?