Skip to content

Instantly share code, notes, and snippets.

@alsamitech
Created April 5, 2021 06:53
Show Gist options
  • Select an option

  • Save alsamitech/eb8eddda96bd6dc11e463406640ca369 to your computer and use it in GitHub Desktop.

Select an option

Save alsamitech/eb8eddda96bd6dc11e463406640ca369 to your computer and use it in GitHub Desktop.
Simply reads from file descripter one (stdin) for as long as it goes, similar to cin.getline in C++, just thought I'd add this.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef __unix__
#include <unistd.h>
#else
#error Only supports unix!
#endif
int main(int argc, char** argv){
char x[10];
int n;
while((n=read(0, x, 8))>0){
printf("\033[1;31m%d %s\033[0m\n", n, x);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment