• Log in or sign up for an account here: https://www.sythe.org/login

echo in C

Faskist

Tuxhead
Banned
Joined
Apr 25, 2005
Sythe Gold
0
Messages
1,869
echo in C
Code:
#include <stdio.h> 
int main(int argc, char *argv[]) {
  int i;
  for(i=1;i<argc;i++) {
    printf("%s",&argv[i][0]);
    if(!(i+1==argc)) {
      printf(" ");
    }
  }
  printf("\n");
}
Written by me and Fouisgras over MSN :3

Can take an arbitrary number of arguments, but doesn't die on 0 args (Just prints newline, which is sad). Any help on detecting a 0 number of arguments would be much appreciated.
 
echo in C
:3 horray.
 
echo in C
So it practically just prints out the command line arguments?
 
echo in C
Code:
#include <stdio.h> 
#include <ctype.h>
int main(int argc, char *argv[]) {
  int i;
  if(argv[1]!=NULL) { // If there are arguments
    for(i=1;i<argc;i++) {
      printf("%s ",&argv[i][0]); // Loop through the arguments printing them
    }
  }
  else { // If no arguments
    for(i=0;i<sizeof(argv[0]);i++) {
      argv[0][i] = toupper(argv[0][i]); // Take the [0] argument which will be the name of the command and make it uppercase
    }
    printf("%s is on.\n", argv[0]); // Print out "<name of command> is on" just as echo does when there are no arguments
  }
}
Made a couple minor changes and added detection for zero arguments like the real 'echo' has. Also, commented it but I think that's mostly to help out Fouis. ;)
 
echo in C
Thanks null :D
 
echo in C
UNIX and Windows both already have an echo command... >_>
 
echo in C
Yet inefficient. Ours is smaller. Less bloated is always win.

Anyway it wasn't meant to be fully function. It was mainly an excercise.

GTFO :(
 
echo in C
UNIX and Windows both already have an echo command... >_>
We know :3 But ours is small and sexy, and the GNU one is massive.
 
Runescape Gamblingrunescape gambling
Back
Top