c - Printing a string due to a new line -


is there efficient (- in terms of performance) way printing arbitrary string, until first new line character in (excluding new line character) ?


example:

char *string = "hello\nworld\n";  printf(foo(string + 6)); 

output:

world

if concerned performance might (untested code):

void myprint(const char *str) {   int len = strlen(str) + 1;   char *temp = alloca(len);    int i;   (i = 0; < len; i++)   {     char ch = str[i];     if (ch == '\n')       break;     temp[i] = ch;   }    temp[i] = 0;    puts(temp); } 

strlen fast, alloca fast, copying string first \n fast, puts faster printf is far slower 3 operations mentioned before together.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -