Quick injection of data in C without 3rd party functions -
this code made. objective @ first make abcdef appear on screen least amount of code possible given abc 1 memory space , def memory space.
#include "stdio.h" void catstring3(){ char space[10]; char toadd[5]={'d','e','f','\0'}; char *string=space; char *addon=toadd; *string++='a'; *string++='b'; *string++='c'; *string++='def' // how? *string++='\0'; string=space; printf("result: %s\n",string); } void catstring(){ char space[10]; char toadd[5]={'d','e','f','\0'}; char *string=space; char *addon=toadd; *string++='a'; *string++='b'; *string++='c'; while (*addon!='\0'){ *string++=*addon++; } *string++='\0'; string=space; printf("result: %s\n",string); } void catstring2(){ char space[10]; char *string=space; *string++='a'; *string++='b'; *string++='c'; *string++='d'; *string++='e'; *string++='f'; *string++='\0'; string=space; printf("result: %s\n",string); } int main(int argc,char* argv[]){ catstring(); catstring2(); catstring3(); return 0; }
of functions, feel function catstring2 produce slowest results because i'm setting values of each string space , added 1 line of code (one line per character of string). catstring bit cleaner processing wise, still same. catstring3 not execute @ //how?
line because in conventional c can't assign string variable expecting one-character value.
what want assign @ least 2 bytes of data string pointer @ least 2 bytes modified @ once in string without use of third party functions such strcpy , memcpy , strcat.
anyone know easiest way or stuck setting 1 character @ time?
Comments
Post a Comment