Sample C programming code. How to get input from the console.

This is a sample C program showing how to define a function as well as accepting input from the command-line. Hopefully this is useful for someone who is writing a console application for Linux or UNIX.

#include <stdio.h>
#include <string.h>

#define MSG "World"

int goku(void) {
	printf("Hello %s.\n", MSG);
	return 1;

int main(int argc, char **argv) {

	char *name;

	name = argv[1];

	if (strlen(name) < 5) {
		printf("Name too short.\n");
	printf("%s\n", name);
	return 0;

No comments have been made. Use this form to start the conversation :)

Leave a Reply