Overwrite the newline character in string : String Terminator « String « C Tutorial






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

int main(void)
{
  char text[100];                

  printf("\nEnter the string to be searched(less than 100 characters):\n");
  fgets(text, sizeof(text), stdin);

  text[strlen(text)-1] = '\0';

  printf("%s",text);

}
Enter the string to be searched(less than 100 characters):
     string
     string








3.2.String Terminator
3.2.1.Displaying a string with a string terminator in the middle
3.2.2.Overwrite the newline character in string
3.2.3.By setting first[4] to NULL ('\0'), we can shorten the string