Patrick Dwyer

Echo :: C

in News, Comparative Programming, C by patrick

This program is part of the Comparative Programming :: Echo set of examples.

The C example is similar in nature to most of the other examples so far; a for loop iterates through the available arguments as passed in via the command line. As C doesn’t have an explicit method for joining a series of strings together, like a number of other examples so far, we print out each argument followed by a space. The program finished with a newline.

This is also our first example that needs to be compiled into a native binary. While this does make the code non-portable, restricting it to the architecture we compiled it on, it also means that we don’t need an iterpreter to run it.

#include <stdio.h>

int main(int argc, char* argv[]) {
int i;
for (i = 1; i < argc; i++) {
printf("%s ", argv[i]);

Program Source: echo.c

Compiling the example

From the command line:

gcc echoc -o echo_c

Running the example

From the command line:

./echo_c Hello World