How can I back up the string in its original form? I'm using strncpy() but, however when I try to print the sentence the original text is altered. Here is an example: if I entered "This is a sample text" for gets and ask to print the sentence, the console prints "TTTTs is a ample ttxt". Can someone tell how to make it so that the sentenceBackup variable has a backup and the sentence is correctly displayed as entered.
//String variable to contain the user input.
char sentence[] = "";
char sentenceBackup[] ="";
//this variable tracks the size of the user input.
int sentenceLength;
//ask the user forsinput
printf("Enter a free formed sentence that needs to be sorted: \n");
//accept the user entry into sentence.
//scanf is deprecated since C11.
gets(sentence);
// keep a backup for further operation.
strncpy(sentenceBackup, sentence, findLength(sentence));
//display the sentence entered.
printf("The sentence is : %s\n", sentence);
Ps: If I take off the strncpy() method, the source text,i.e sentence variable is correctly displayed.