Write a function that takes acharacter and a character array containing a null-t
ID: 3611223 • Letter: W
Question
Write a function that takes acharacter and a character array containing a null-terminated string(that does not fill the entire arrayparameter) andcopies each character in the string to the next position in thecharacter array and stores the character into the beginning(0th element) of the array.Essentially, it takes in a char, and thearray that the char will be inserted into. It scoots all ofthe chars in the array to the right one, and then takes the charthat is being passed in as a parameter ... and inserts it into thearray at the front (0th position). Pretty much adding to thefront of the array by scooting everything else down one, makingroom for the char to be inserted.
Explanation / Answer
please rate - thanks hope this is what your looking for #include #include #include void shiftit(char,char[]); int main(){ char ch='a', array[50]="This is an example"; printf("%s ",array); shiftit(ch,array); printf("%s ",array); getch(); return 0; } void shiftit(char a,char arr[]) {int j; for(j=strlen(arr);j>=0;j--) arr[j+1]=arr[j]; arr[0]=a; return; }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.