Skip to content

Instantly share code, notes, and snippets.

@jnikolak
Created October 16, 2017 01:02
Show Gist options
  • Save jnikolak/bf9306d700c490e43cb6e476f62d683b to your computer and use it in GitHub Desktop.
Save jnikolak/bf9306d700c490e43cb6e476f62d683b to your computer and use it in GitHub Desktop.
Shell Prompt
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void prompt();
int main()
{
char hostname[1024];
gethostname(hostname, 1024);
int loop = 0;
char input[32];
while(1)
{
prompt();
fgets(input,31,stdin);
loop++;
}
return(0);
}
/* Display prompt */
void prompt()
{
char hostname[1024];
gethostname(hostname, 10);
printf("[root@%s]# ",hostname);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment