English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

how do i add char first[20]="rob" and last[20]="mah" in third array char fullname[2*20]="rob mah" . our semester ended with array we haven't even finished sorting searching and strings as well so how do i append this using function or passing array to the function.

2007-05-10 06:53:10 · 2 answers · asked by robin m 1 in Computers & Internet Programming & Design

2 answers

strcpy(fullname, fn);//copy first name to full name string
strcat(fullname, ln);//add last name to the end of full name

2007-05-11 00:43:08 · answer #1 · answered by justme 7 · 0 0

You need a function that copies strings, for example snprintf(). It works just like printf, i.e. you can format text and include other strings and numbers, but then puts the output in a different string/array.
char fn[20]="Rob";
char ln[20]="Mah";
char both[2*20];
snprintf( both, "%s %s", fn, ln );

What this does is it replaces the first %s with the first argument that follows (fn) and the second %s with the second argument (ln). Then places a space between the two and puts the result in both.

2007-05-10 07:42:07 · answer #2 · answered by xfire_2 4 · 0 0

fedest.com, questions and answers