2014年4月14日 星期一

[C] How to pass string to another function


[C] How to pass string to another function



#include <stdio.h>

#include <string.h>



int print(char *src )

{

   char dest[100];

   memset(dest, '\0', sizeof(dest));



   strcpy(dest, src);

   printf("Final copied string : %s\n", dest);



   return 1;

}



int main()

{

   char src[40];



   strcpy(src, "This is tutorialspoint.com");

   print(src);



   return(0);

}



Reference:



Related Posts:

  • [Terminal] Write a basic terminal 1. Download lxterminal from github git clone git@github.com:Jumbo88888/lxterminal.git cd lxterminal/src rm .h && rm .c 2. Write a basic t… Read More
  • [C] strcpy source code strcpy.c [plain text] /* * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * The contents o… Read More
  • [C] Implement - thread qemu-thread.c /* * Wrappers around mutex/cond/thread functions * * Copyright Red Hat, Inc. 2009 * * Author: * Marcelo Tosatti <mtosatti@re… Read More
  • [C] Coding skill - !!x "!!x" 這樣就可以保證不管 x 的輸入是什麼,最終輸出只有 0 或 1 #include<stdio.h> int main() { int x=0x00; int y=0x0a; printf("x = %d",!!x); printf("y = %d"… Read More
  • [C] Define Error Code struct errmsg { int e_code; char *e_msg; } errmsgs[] = { { EUNDEF, "Undefined error code" }, { ENOTFOUN… Read More

0 意見:

張貼留言