Sample C language programming on Linux system

Printing ‘ Hello World ‘

 

1. Coding

Linux $ nano sample-c.c

#include
main() {
char *cp;
char buf[]="Hello World";
/* Make cp point to Hello\0 */
cp = strtok(buf, " ");
printf(“%s\n”, cp);
/* Now make cp point to World\0 */
cp = strtok(NULL, " ");
printf(“%s\n”, cp);
/* Now make cp point NULL */
cp = strtok(NULL, " ");
}

 

2. Compiling

Linux $ gcc -o mystrtoc mystrtoc.c
 

 

3. Executing

Linux $ ./sample-c

 

4. Outbut

Hello
World

Leave a Reply