Answer to Question #292700 in C for Sasi

Question #292700

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####

1
Expert's answer
2022-02-01T04:11:24-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS