![]() ![]() ![]() | strings/string-ptr-2.c - Et tilsvarende program, kortere og mere kryptisk - for 'rigtige C programmører'. | Lektion 10 - slide 17 : 51 Program 2 |
#include <stdio.h> int main(void) { char str_aal[] = "Aalborg"; char str[14]; char *str_1, *str_2; int i; /* fill str with '-' */ for(i = 0; i < 14; i++) str[i] = '-'; /* let str_1 and str_2 be pointers to target and source resp. */ str_1 = str + 2; str_2 = str_aal; /* copy str_all into the middle of str */ while(*str_1++ = *str_2++); printf("%s\n", str); return 0; }