1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
void full_name(char *p_name, char *p_lastname1, char *p_lastname2, char *p_finalname) {
int i=0, j=0;
while(p_lastname1[j]){
p_finalname[i++]=p_lastname1[j++];
}
p_finalname[i++]=' '; //Adds a space
j=0;
while(p_lastname2[j]) {
p_finalname[i++]=p_lastname2[j++];
}
p_finalname[i++]=', '; //Adds a comma
p_finalname[i++]=' '; //Adds a space
j=0;
while(p_name[j]){
p_finalname[i++]=p_name[j++];
}
p_finalname[i]='\0';
}
int main()
{
char name[1024], lastname1[1024], lastname2[1024], finalname[1024];
char *p_name=&name[0];
char *p_lastname1=&lastname1[0];
char *p_lastname2=&lastname2[0];
char *p_finalname=&finalname[0];
printf("Insert the name: ");
scanf("%s", p_name);
printf("Insert the first last name: ");
scanf("%s", p_lastname1);
printf("Insert the second last name: ");
scanf("%s", p_lastname2);
full_name(p_name,p_lastname1,p_lastname2,p_finalname);
printf("The complete name is %s",p_finalname);
return 0;
}
|