When I use fgets() function to take input the string,the The result gave a garbage value at the end. But when I use gets() or scanf() function then the program work perfectly and accepted by the judge. I can't understand the issues while using fgets () to take input.
#include<stdio.h>
#include<string.h>
int main()
{
int k,i;
char s[100];
fgets (s,sizeof(s),stdin);
scanf("%d",&k);
for(i=0;s[i]!='\0';i++)
{
if( (s[i]-k)<65)
{
printf("%c",s[i]+26-k);
}
else printf("%c",s[i]-k);
}
return 0;
}