string - append or replace last char by dynamic number in C without libraries (avr-gcc) -
i'm programming microcontroller , dynamically generate string.
basically desire following:
char * string = "app"; for(uint8_t i=0;i<max;i++){ char * newstring = app + i; printf("%s \n",newstring); }
and should print app1, app2, app3, ... know there libraries manipulate strings, i'm working on microcontroller avr-gcc , keep code size minimal.
i've been messing around pointers , arrays, can't work.
edit: tried like:
char * path = "application/app "; path[2]=(char) '1'; rest_activate_resource(&coap_app_res[coap_app_res_nb], path);
but prints "aplication/app " (without 2nd p).
to manipulate strings, first of strings must modifiable. string literals aren't modifiable.
the first example can implemented this:
char string[] = "appx"; /* x used placeholder */ for(uint8_t i=0;i<max;i++){ string[3] = + '0'; /* assign character x */ printf("%s \n",string); }
Comments
Post a Comment