Skip to content

Instantly share code, notes, and snippets.

@lsparrish
Created September 15, 2010 00:40
Show Gist options
  • Select an option

  • Save lsparrish/580046 to your computer and use it in GitHub Desktop.

Select an option

Save lsparrish/580046 to your computer and use it in GitHub Desktop.
playing around with c
#include <stdio.h>
char* listen();
int process();
int strcmp();
int output();
int main() {
char *str;
while (strcmp(str,"bye\n") != 0){
str=listen();
process(str);
}
return 0;
}
char str [1024];
char* listen(){
char *p; p=str; /* initialize pointer */
/* this increments the pointer after doing getc
then compares to see if it is a newline char: */
while((*p++=(getc(stdin)))!='\n');
*p=0; /* make sure it knows where to end the string */
return str;
}
int process(char *str){
output(str);
return 0;
}
int output(char *str){
char *p; p=str; /* initialize pointer */
while((putc(*p++,stdout))!=0);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment