When I use "fgets" (in gcc) it saves new line character within the entered string, I want to remove the new line character.
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char x[10];
fgets(x,10,stdin);
cout << x << endl;
return 0;
}
From comments I went to Removing trailing newline character from fgets() input
and I used "strcspn" and it works fine like:
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main()
{
char x[20];
fgets(x,sizeof(x),stdin);
x[strcspn(x,"\n")]=0;
cout << x << endl;
if(!strcmp(x,"hello world!"))
{
cout << "yes" << endl;
}
return 0;
}