Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C by TOL ( 18 years ago )
ЛиÑтинг 4.8. concat.c (ÐºÐ¾Ð½ÐºÐ°Ñ‚ÐµÐ½Ð°Ñ†Ð¸Ñ Ñтрок)
1: #include <stdio.h>
2: #include <stdlib.h>
3: #include <conio.h>
4: #include <string.h>
5: #include <alloc.h>
6: #include "gets.h"
7:
8: char *PromptFor(char *prompt);
9:
10: int main(void)
11: {
12: char *firstName;
13: char *middleName;
14: char *lastName;
15: char fullName[128];
16:
17: clrscr();
18: firstName = PromptFor("first name");
19: middleName = PromptFor("middle name");
20: lastName = PromptFor("last name");
21: strcpy(fullName, firstName);
22: strcat(fullName, " ");
23: strcat(fullName, middleName);
24: strcat(fullName, " ");
25: strcat(fullName, lastName);
26: printf ("Your name is: %s", fullName);
27: free(firstName); /* оÑвобождает */
28: free(middleName); /* выделенную */
29: free(lastName); /* памÑть */
30: return 0;
31: }
32:
33: char *PromptFor(char *prompt)
34: {
35: char *temp; /* временный Ñтроковый указатель */
36:
37: printf("Enter your %s: ", prompt);
38: temp = GetStringAt(MAXLEN);
39: if (!temp) {
40: puts("
Error: Out of memory");
41: exit(1);
42: }
43: return temp;
44: }
Revise this Paste