Expert Q&A; Done Write an LC-3 arbitrarily-long string (array) of characters and
ID: 3914868 • Letter: E
Question
Expert Q&A; Done Write an LC-3 arbitrarily-long string (array) of characters and store it in memory. It will then rotate the characters one position to the left. It will print the rotated string, and repeat rotating and printing until all the possible rotations have been printed. For example Enter a string: a Rotated strings: abcdef bedefa cdefab defabc efabcd fabcde End of processing. program that will read in an bcdef A few implementation requirements: Your program must rotate the strings in memory: that is, change the contents of memory and print the string using PUTS. Your program should read input into the string until the end-of-line character (#10) is entered. Your program only needs to process a single input value each time it is run. Hint: because you don't know the length of the string in advance, make it the last data value in your program so it does not overwrite anything elseExplanation / Answer
#include<stdio.h>
#include<string.h>//string library to use string inbuilt function like strlen,strcpy here
int main(){
//S is original string that is entered by user
//R is the rotated string that will have the rotated string every time.
char S[10000],R[10000],fchar;
int len,i,l;
printf("Enter the string: ");
scanf("%s[^ ] ",S);//accept the string until line changes
printf("Rotated string : ");
strcpy(R,S);//copy content of string S to string R
//strcpy(destination,source);
len=strlen(R);//stores length of the string R,it can be strlen(S) also because after rotation also length is same
puts(S); //print string with 0 rotation
l=1;//variable that stores the count that rotation must not exceeds the number of length as after that it will again provide the input string
while(l<len){//while loop to check that it terminates if l becomes greater or equal than length
fchar=R[0];//fchar store variable at 0 position so that after shifting one left it never get missed.
for(i=1;i<len;i++){//shifting one by one to previous index
R[i-1]=R[i];
}
R[len-1]=fchar;//after shifting rotated string R will have same value in last index and last-1 index so we will replace last by fchar variable
puts(R);//print rotated string R and changes line
l++;//incrementation
}
printf("End of processing.");
return 0;//return nothing
//you can remove return and change int main to void main
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.