Answer to Question #56519 in C for rajashree g.s.

Question #56519
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.
1
Expert's answer
2016-01-19T08:28:40-0500
#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!

Comments

Assignment Expert
01.03.16, 17:33

Dear Hamna, Answer to this question presupposes a lot of work, so it can be submitted as a task on our website. Our experts will offer you quotes shortly and you will have it done by your deadline. Please follow this link https://www.assignmentexpert.com/assignments/#signup We will be looking forward to receiving your assignment.

Assignment Expert
01.03.16, 17:32

Dear Customer, the answer to this question presupposes a lot of work, so it can be submitted as a task on our website. Our experts will offer you quotes shortly and you will have it done by your deadline.

rajashree g.s
29.02.16, 16:08

i dont know the code for the above program. that's whiy i posted the question. when i compiled the above program i got the errors. its not working properly. if you know the answer please email it to me.

Assignment Expert
29.02.16, 15:55

Dear Hamna, program works as following: Please enter name 0 :aaa Please enter name 1 :bbb Please enter name 2 :ccc Please enter name 3 :ddd Please enter name 4 :eee Please enter prefix:QQ QQaaa QQbbb QQccc QQddd QQeee So, it works according to the given task.

hamna
27.02.16, 16:48

the answer of the question given above is not correct ! kindly give the correct answer

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS