2011-05-12 19:42:00 #include <stdlib.h> #include <stdio.h> #include <string.h> #include <unistd.h> #include <sys/types.h> #include <fcntl.h> #include <sys/time.h> #include <sys/select.h> #include <signal.h> #define MAX_BUF_LEN 128 #define FTPC_CMD_LEN 8 #define FTPC_PARAM_LEN 64 #define MAX_USER_NAME 16 #define MAX_USER_PASSWD 16 int get_name_passwd(char *usr_name,char *usr_passwd) { int n_read; if((usr_name == NULL) || (usr_passwd == NULL)){ printf("user's name or password is NULL in function[get_name_passwd]n"); return -1; } printf("please input your name:"); fflush(stdout); // stdout:输出流指针 n_read = read(1, usr_name, MAX_USER_NAME); // 1:STD_OUT usr_name[n_read-1] = '/0'; printf("please input your password:"); fflush(stdout); n_read = read(1, usr_passwd, MAX_USER_PASSWD); usr_passwd[n_read-1] = '/0'; return 0; } int main(int argc, char **argv) { char usr_name[MAX_BUF_LEN]; char usr_passwd[MAX_BUF_LEN]; get_name_passwd(usr_name, usr_passwd); printf("%s, %s/n", usr_name, usr_passwd); fflush(stdout); return 0; }