
不成熟的代码如下:
代码: 全选
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <grp.h>
#include <signal.h>
#define SIGSTCP 20
void cd();
void dir();
int main(){
char buf[80],prompt[100];
char tmp[80];
memset(tmp, 0, sizeof(tmp));
char *username;
struct group *data;
data = getgrgid(getgid());
username = data->gr_name="WLLY";
strcat(tmp, "/home/");
strcat(tmp, username);
printf("-------------*Welcome*-------------\n");
while(1) {
getcwd(buf, sizeof(buf));
memset(buf, 0, sizeof(buf));
buf[0] = '~';
buf[1] = '\0';
sprintf(prompt,"%s:%s$", username, buf);
// printf("%s",prompt);
int c;
c=getchar();
if(c=='A')
cd();
else{
if (c=='B')
dir();
else
printf("%s",prompt);}
}
// strcat(prompt,username);
// strcat(prompt,":");
// strcat(prompt,buf);
// strcat(prompt,"$");
// printf("%s",prompt);
}
void cd(){
printf("hgrtgf");
printf("\n");
}
void dir(){
printf("gvryhdf");
printf("\n");
}