0

Can we concatenate two character and store in another char or character array to print a string in C ?

as like: char str[]={"aabababcab"}; char p=str[1]; char q=str[2]; char r=strcat(p,q); printf("%c",r);. //%s desirable output is:. ab

7th Sep 2018, 7:48 AM
deepanshu samdani
deepanshu samdani - avatar
1 Réponse
+ 1
Sorry but strcat append a string to another one and dont that you think... You can use the strncpy function for this http://www.cplusplus.com/reference/cstring/strncpy/ or better make all " to hand" char str[]= "aabababcab"; char r[3]={0}; // r is 3 size for contain null // terminator char // strncpy way strncpy(r, str+1, 2); // or using direct copy r[0]=str[1]; r[1]= str[2];
7th Sep 2018, 8:51 AM
KrOW
KrOW - avatar