write a c program to accept 5 names and a prefix.Insert the prefix at the beginning of each name in the array.Display the modified names.
#include <stdio.h>
#define MAX_LENGTH 1024
#define N 5
int main(void) {
char names[N][MAX_LENGTH];
for(int i = 0; i < N; ++i) {
printf("Please enter name %d :", i);
scanf("%s", names[i]);
}
char prefix[MAX_LENGTH];
printf("Please enter prefix:");
scanf("%s", prefix);
int prefixLen = strlen(prefix);
for(int i = 0; i < N; ++i) {
strcpy(names[i] + prefixLen, names[i]);
strncpy(names[i], prefix, prefixLen);
printf("%s\r\n", names[i]);
}
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!
Learn more about our help with Assignments:
C