I'm suppose to print an abbreviated version of words that are strictly larger than 10 ("first letter", number of letters between the first letter and the last letter, "last letter" for ex - international should become i11l ), if not than print the word as it is. I'm able to do it using scanf.
scanf("\n%s", longWord);
but when I try to read the string with fgets, I'm not getting the desired output. (it doesn't show any error though), I'm not sure if the problem is with reading the input or generating the desired formatted output.
I'm new to programming and I'm having hard time understanding strings and their manipulations. Any help will be appreciated.
#include<stdio.h>
#include<string.h>
#define buffer_size 100
int main()
{
int n;
scanf("%d", &n);
while(n--)
{
char longWord[buffer_size];
int wordSize;
fgets(longWord, sizeof(longWord), stdin);
wordSize = strlen(longWord);
if(wordSize > 10)
{
printf("\n%c%d%c", longWord[0], wordSize-2, longWord[wordSize-1]);
}
else
{
printf("\n%s", longWord);
}
}
return 0;
}