Online Compiler C

#include <stdio.h> #include <string.h> int main() { long long int k; char a[1001],b[1001]; scanf("%lld", &k); scanf("%[^\n]", a); int lon = strlen(a); if(k > lon) { k = k % lon; } for(int i = 0; i< lon -k; i++) { b[i+lon] = a[i]; } for(int i = lon - k; i< lon; i++) { j = 0; b[j] = a[i]; j++; } for(int i = 0; i < len; i++) { print("%c", b[i]); } return 0; }
This code attempts to rotate a string to the right by k positions, but has several errors. The program reads an integer k and a string a, then tries to build a rotated version in array b and print it.

- The variable j is used without being declared. You need to declare j before using it, and also reset it properly for the second loop.
- The first loop writes to b[i+lon] which is outside the array bounds. You likely meant to copy the first part of the string to the beginning of b, not beyond its end.
- The second loop has j = 0 inside the loop, which resets j each iteration. You probably want to set j = 0 once before the loop starts.
- The print function should be printf, not print.
- The variable len in the final loop is not defined; you probably meant lon.