I created a program rotate.c to do the following but it has some bugs. Can you f
ID: 3620131 • Letter: I
Question
I created a program rotate.c to do the following but it has some bugs. Can you fix the bugs and write comments on how you fixed them./*
* rotate.c
*
* This program is supposed to print get an input string
* from the user, then print it rotated on the line.
* Example:
* Enter a string for me to rotate: I love CSE240!!!
* I Love CSE240!!!
* Love CSE240!!!I
* Love CSE240!!!I
* ove CSE240!!!I L
* ve CSE240!!!I Lo
* e CSE240!!!I Lov
* CSE240!!!I Love
* CSE240!!!I Love
* SE240!!!I Love C
* E240!!!I Love CS
* 240!!!I Love CSE
* 40!!!I Love CSE2
* 0!!!I Love CSE24
* !!!I Love CSE240
* !!I Love CSE240!
* !I Love CSE240!!
* I Love CSE240!!!
*
* WARNING: This code contains several BUGS!
*/
#include <stdio.h>
#include <string.h>
int main()
{
int len;
int lineno;
int i = 0;
char input[256];
printf("Enter a string for me to rotate: ");
/* This scanf format string specifies that scanf
should read a string of max length 255. It also
specifies that scanf should consider any characters
that are not tab or newline as part of the string
(that way we can have spaces). Something to ask
yourself: why is the max length 255 and not 256? */
scanf("%[^ ]255s", input);
len = strlen(input);
for (lineno = 0; lineno < len; lineno = lineno + 1) {
i = lineno;
while (input[i] != '') {
printf("%s", input[i]);
i = i + 1;
}
for (i = 1 ; i < lineno; i++) {
printf("%s", input[i]);
}
putchar(' ');
}
printf("%s ", input);
return 0;
}
Explanation / Answer
please rate - thanks changes in rednotice how the indenting makes the program easier to read
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.