Design a c program the embed special characters as leading and trailing to the input string and display the output
Input:
Strnset
#
4
Output:
####set
Str####
#include <stdio.h>
#include <string.h>
int main() {
char buf[1024];
char ch;
int n, len, i;
scanf("%s", buf);
scanf(" %c", &ch);
scanf("%d", &n);
len = strlen(buf);
n = n < len ? n : len; /* n = min(n, len) */
for (i=0; i<len; i++) {
putchar(i<n ? ch : buf[i]);
}
putchar('\n');
for (i=0; i<len; i++) {
putchar(i<len-n ? buf[i] : ch);
}
putchar('\n');
return 0;
}
Comments
Leave a comment