您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ Fgets函数代码示例

51自学网 2021-06-01 20:45:54
  C++
这篇教程C++ Fgets函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中Fgets函数的典型用法代码示例。如果您正苦于以下问题:C++ Fgets函数的具体用法?C++ Fgets怎么用?C++ Fgets使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了Fgets函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char *argv[]){      	if(signal(SIGTSTP,handler)==SIG_ERR||signal(SIGINT,handler) == SIG_ERR)        	unix_error("signal error");    char cmdline[MAXLINE];	printf("%s/n","We have following commands in our main system: ");    printf("%s/n","help/t we are glad to offer you our best services...");    printf("%s/n","checkin/t welcome to join our Oxford Heights Community...");    printf("%s/n","checkout/t we are sorry to see you are leaving us...");    printf("%s/n","payrent/t thanks for being our loyal tenants...");    printf("%s/n","info/t get to know our super developer...");    printf("%s/n","IAmTheBoss/t to exit this system...");   	printf("type 0 to return to main system:");	Fgets(cmdline, MAXLINE, stdin);	if(feof(stdin))		exit(0);	while( strcmp(cmdline, "0/n") != 0 ){	   	printf("type 0 to return to main system:");		Fgets(cmdline, MAXLINE, stdin);		if(feof(stdin))			exit(0);	}    exit(EXIT_SUCCESS);}
开发者ID:jiuningzhong,项目名称:proj01,代码行数:30,


示例2: main

int main(int argc,char ** argv){	int  n;	FILE *fp;	char buff[MAXLINE],command[MAXLINE];	if(Fgets(buff,MAXLINE,stdin)==NULL)		err_quit("input error");	n=strlen(buff);	if(buff[n-1]=='/n')		buff[n-1]=0;	snprintf(command,sizeof(command),"cat %s",buff);	fp=Popen(command,"r");	while(Fgets(buff,MAXLINE,fp)!=NULL)		Fputs(buff,stdout);	Pclose(fp);	exit(0);}
开发者ID:woai110120130,项目名称:unix,代码行数:26,


示例3: str_cli

voidstr_cli (FILE *fp, int sockfd) {	int maxfdp1;	fd_set rset;	char sendline[MAXLINE], recvline[MAXLINE];	FD_ZERO(&rset);	for (;;) {		FD_SET (fileno(fp), &rset);		FD_SET (sockfd, &rset);		maxfdp1 = MAX (fileno(fp), sockfd) + 1;		Select (maxfdp1, &rset, NULL, NULL, NULL);		if (FD_ISSET (sockfd, &rset)) {			if (Readline (sockfd, recvline, MAXLINE) == 0) {				err_quit ("str_cli: server terminated prematurely");			}			Fputs (recvline, stdout);		}		if (FD_ISSET (fileno(fp), &rset)) {			if (Fgets (sendline, MAXLINE, fp) == NULL) {				return;			}			Writen (sockfd, sendline, strlen(sendline));		}	}}
开发者ID:4179e1,项目名称:misc,代码行数:29,


示例4: ftp_command

int ftp_command(char *buf,int success,FILE *out,char *fmt,...){    va_list va;    char line[1200];    int val;    va_start(va,fmt);    vsprintf(line,fmt,va);    va_end(va);    if (write(fileno(out),line,strlen(line)) < 0)        return(-1);    bzero(buf,200);    while(1) {        Fgets(line,sizeof(line),out);#ifdef DEBUG        printf("%s",line);#endif        if (*(line+3)!='-') break;    }    strncpy(buf,line,200);    val = atoi(line);    if (success != val) return(-1);    return(1);}
开发者ID:B-Rich,项目名称:exploit-database,代码行数:26,


示例5: dg_cli

/*signal occur must in recvfrom ,or it must be a dead cycle*/void dg_cli(FILE *fp,int sockfd,const SA *pservaddr,socklen_t servlen){	int n;	const in on = 1;	char sendline[MAXLINE+1],recvline[MAXLINE+1];	socklen_t len;	struct sockaddr_in *preply_addr;	preply_addr = malloc(sizeof(struct sockaddr_in));	bzero(preply_addr);	SetSockopt(sockfd,SOL_SOCKET,SO_BROADCAST,&on,sizeof(on));	Signal(SIGALAM,recvfrom_alarm);	len = servlen;	while(Fgets(sendline,MAXLINE,fp) != NULL){		sendto(sockfd,sendline,strlen(sendline),0,pservaddr,len);		alarm(5);		for(;;){			len=servlen;			n = recvfrom(sockfd,recvlien,MAXLINE,0,preply_addr,&len);			if(n < 0){				if(errno == EINTR)					break;				else					err_quit("recvfrom error!");			}else{				recvfrom[n] = 0;				printf("from %s : %s",inet_ntop(preply_addr->sin_family,preply_addr->sin_addr.s_addr,preply_addr->sin_len),recvfrom);			}		}	}}
开发者ID:hu010354,项目名称:kaizer,代码行数:32,


示例6: main

int main(int argc, char **argv) {    int clientfd, port;    char *host, buf[MAXLINE];    rio_t rio;    if (argc != 3) {	fprintf(stderr, "usage: %s <host> <port>/n", argv[0]);	exit(0);    }    host = argv[1];    port = atoi(argv[2]);    clientfd = Open_clientfd(host, port);    Rio_readinitb(&rio, clientfd);    while (Fgets(buf, MAXLINE, stdin) != NULL) {    printf("client get: %s/n",buf);	Rio_writen(clientfd, buf, strlen(buf));    printf("client buf: %s/n",buf);	Rio_readlineb(&rio, buf, MAXLINE);	Fputs(buf, stdout);    }    //    printf("outside/n");    Close(clientfd); //line:netp:echoclient:close    exit(0);}
开发者ID:MujingZhou,项目名称:Apr.2015_Caching-Web-Proxy,代码行数:28,


示例7: dg_cli

voiddg_cli(FILE *fp, int sockfd, const SA *pservaddr, socklen_t servlen){	int	n;	char	sendline[MAXLINE], recvline[MAXLINE + 1];	socklen_t		len;	struct sockaddr	*preply_addr;	preply_addr = Malloc(servlen);	while (Fgets(sendline, MAXLINE, fp) != NULL) {		Sendto(sockfd, sendline, strlen(sendline), 0, pservaddr, servlen);		len = servlen;		n = Recvfrom(sockfd, recvline, MAXLINE, 0, preply_addr, &len);		if (len != servlen || memcmp(pservaddr, preply_addr, len) != 0) {			printf("reply from %s (ignored)/n",					Sock_ntop(preply_addr, len));			continue;		}		recvline[n] = 0;	/* null terminate */		Fputs(recvline, stdout);	}}
开发者ID:elftech,项目名称:vmware-code,代码行数:26,


示例8: client

void client(int readfd, int writefd){	size_t len;	ssize_t n;	char *ptr;	struct mymesg mesg;	//start buffer with pid and a blank	snprintf(mesg.mesg_data, MAXMESGDATA, "%ld", (long) getpid());	len = strlen(mesg.mesg_data);	ptr = mesg.mesg_data + len;	// read pathname	Fgets(ptr, MAXMESGDATA - len, stdin);	len = strlen(mesg.mesg_data);	if (mesg.mesg_data[len-1] == '/n')		len--;	mesg.mesg_len = len;	mesg.mesg_type = 1;	// write PID and pathname to IPC channed	mesg_send(writefd, &mesg);	// read from IPC, write to standard output	mesg.mesg_type = getpid();	while ((n = mesg_recv(readfd, &mesg)) > 0)		Write(STDOUT_FILENO, mesg.mesg_data, n);}
开发者ID:crazy-canux,项目名称:cAPI,代码行数:28,


示例9: dg_cli

voiddg_cli(FILE *fp, int sockfd, const SA *pservaddr, socklen_t servlen){    int	n;    char	sendline[MAXLINE], recvline[MAXLINE + 1];    Signal(SIGALRM, sig_alrm);    while (Fgets(sendline, MAXLINE, fp) != NULL)    {        Sendto(sockfd, sendline, strlen(sendline), 0, pservaddr, servlen);        alarm(5);        if ( (n = recvfrom(sockfd, recvline, MAXLINE, 0, NULL, NULL)) < 0)        {            if (errno == EINTR)                fprintf(stderr, "socket timeout/n");            else                err_sys("recvfrom error");        }        else        {            alarm(0);            recvline[n] = 0;	/* null terminate */            Fputs(recvline, stdout);        }    }}
开发者ID:as2120,项目名称:ZAchieve,代码行数:29,


示例10: fopen

void interaction::traceFname() {    FILE* fFname = fopen(ipHostFname,"r");    if(fFname==NULL) {        sys_err("call to fopen() failed");    }    // read till the end of file    char* pch;    const char* delim=" ";    while(Fgets(ipHostFname, BUFSIZE, fFname)==1) {        //---------------------------------        // remove '/n' at the end of string        //---------------------------------        ipHostFname[strlen(ipHostFname)-1]=0;        pch = strtok(ipHostFname,delim);        //--------------------------------------------------------        //This magic number 'ipHostFname+strlen(ipHostFname)+1' is        //the address of strings followed 'traceroute'        //--------------------------------------------------------        char* magic = ipHostFname+strlen(ipHostFname)+1;        if(strcmp(pch,"traceroute")==0) {            // check if traceroute 'me'            if(strcmp(magic,"me")==0) {                traceMe();            } else {                traceIpHost(magic);            }        } else {            dprintf(connfd, "INVALID INPUT in file: %s %s", ipHostFname, magic);        }    }    fclose(fFname);}
开发者ID:ryanzhao,项目名称:tracerouteServer,代码行数:32,


示例11: server

voidserver(int readfd, int writefd){	FILE	*fp;	ssize_t	n;	struct mymesg	mesg;		/* 4read pathname from IPC channel */	mesg.mesg_type = 1;	if ( (n = Mesg_recv(readfd, &mesg)) == 0)		err_quit("pathname missing");	mesg.mesg_data[n] = '/0';	/* null terminate pathname */	if ( (fp = fopen(mesg.mesg_data, "r")) == NULL) {			/* 4error: must tell client */		snprintf(mesg.mesg_data + n, sizeof(mesg.mesg_data) - n,				 ": can't open, %s/n", strerror(errno));		mesg.mesg_len = strlen(mesg.mesg_data);		Mesg_send(writefd, &mesg);	} else {			/* 4fopen succeeded: copy file to IPC channel */		while (Fgets(mesg.mesg_data, MAXMESGDATA, fp) != NULL) {			mesg.mesg_len = strlen(mesg.mesg_data);			Mesg_send(writefd, &mesg);		}		Fclose(fp);	}		/* 4send a 0-length message to signify the end */	mesg.mesg_len = 0;	Mesg_send(writefd, &mesg);}
开发者ID:piaoyimq,项目名称:CppSpace,代码行数:33,


示例12: dg_cli

void dg_cli(FILE *fp, int sockfd, const SA *pservaddr, socklen_t servlen){	int n;	const int on = 1;	char sendline[MAXLINE], recvline[MAXLINE + 1];	socklen_t len;	struct sockaddr *preply_addr;	preply_addr = (struct sockaddr *)Malloc(servlen);	Setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on));	Signal(SIGALRM, recvfrom_alarm);	while (Fgets(sendline, MAXLINE, fp) != NULL)	{		Sendto(sockfd, sendline, strlen(sendline), 0, pservaddr, servlen);		alarm(5);		for ( ; ; )		{			if (sigsetjmp(jmpbuf, 1) != 0)				break;			len = servlen;			n = Recvfrom(sockfd, recvline, MAXLINE, 0, preply_addr, &len);			recvline[n] = 0;			printf("from %s: %s", (char *)Sock_ntop_host(preply_addr, len), recvline);		}	}	free(preply_addr);}
开发者ID:CanuxCheng,项目名称:UNP1,代码行数:30,


示例13: dg_cli

void dg_cli(FILE *fp, int sockfd, const SA *pservaddr, socklen_t servlen){	int	icmpfd, maxfdp1;	char	sendline[MAXLINE], recvline[MAXLINE + 1];	fd_set	rset;	ssize_t	n;	struct timeval tv;	struct icmpd_err icmpd_err;	struct sockaddr_un sun;	Sock_bind_wild(sockfd, pservaddr->sa_family);	icmpfd = Socket(AF_LOCAL, SOCK_STREAM, 0);	sun.sun_family = AF_LOCAL;	strcpy(sun.sun_path, ICMPD_PATH);	Connect(icmpfd, (SA *)&sun, sizeof(sun));	Write_fd(icmpfd, "1", 1, sockfd);	n = Read(icmpfd, recvline, 1);	if (n != 1 || recvline[0] != '1')		err_quit("error creating icmp socket, n = %d, char = %c",				n, recvline[0]);	FD_ZERO(&rset);	maxfdp1 = max(sockfd, icmpfd) + 1;	while (Fgets(sendline, MAXLINE, fp) != NULL) {		Sendto(sockfd, sendline, strlen(sendline), 0, 				pservaddr, servlen);		tv.tv_sec = 5;		tv.tv_usec = 0;		FD_SET(sockfd, &rset);		FD_SET(icmpfd, &rset);		if ((n = Select(maxfdp1, &rset, NULL, NULL, &tv)) == 0) {			fprintf(stderr, "socket timeout/n");			continue;		}		if (FD_ISSET(sockfd, &rset)) {			n = Recvfrom(sockfd, recvline, MAXLINE, 0, 					NULL, NULL);			recvline[n] = 0;			Fputs(recvline, stdout);		}		if (FD_ISSET(icmpfd, &rset)) {			if ((n = Read(icmpfd, &icmpd_err, 					sizeof(icmpd_err))) == 0)				err_quit("ICMP daemon terminate");			else if (n != sizeof(icmpd_err))				err_quit("n = %d, expected %d",					n, sizeof(icmpd_err));			printf("ICMP error: dest = %s, %s, type = %d,"				" code = %d/n",				Sock_ntop((SA *)&icmpd_err.icmpd_dest,					icmpd_err.icmpd_len),				strerror(icmpd_err.icmpd_errno),				icmpd_err.icmpd_type, 				icmpd_err.icmpd_code);		}	}}
开发者ID:wuzhouhui,项目名称:unp,代码行数:60,


示例14: readcommand

void readcommand(){        // Allocate userpass char array        int i;        for(i = 0; i < 128; i++)	{            execcom[i] = malloc(128);                        }        FILE *file;        char line[128];        i = 0;        file = fopen("rrshcommands.txt", "r");        if (file)        {                while (Fgets(line, sizeof(line), file) != NULL)                {			strtok(line, "/n");                        strcpy(execcom[i], line);                        i++;                }                fclose(file);        }}
开发者ID:kevinlogan94,项目名称:CS_Projects,代码行数:27,


示例15: readconfig

void readconfig(){	// Allocate userpass char array	int i;	int j;        for(i=0; i<2; i++ ){                for(j=0; j<128; j++){                        userpass[i][j] = malloc(40);                }         }        FILE *file;	char line[128];	int c = 0;	char *username;	char *password;        file = fopen("rrshusers.txt", "r");        if (file) 	{                while (Fgets(line, sizeof(line), file) != NULL)		{			char *str = line;			username = strtok(str, " ");			password = strtok(NULL, " ");						strtok(password, "/n");			strcpy(userpass[0][c], username);			strcpy(userpass[1][c], password);				c++;                }                fclose(file);        }}
开发者ID:kevinlogan94,项目名称:CS_Projects,代码行数:35,


示例16: command

void command(void){    char buf[MAXLINE];    if (Fgets(buf, MAXLINE, stdin) == NULL)        exit(0);    Fputs(buf, stdout);}
开发者ID:bsdcpp,项目名称:mylib,代码行数:7,


示例17: CheckConfFileHeader

static voidCheckConfFileHeader (const char sMagic[], const char sFile[], FILE *pFile) // in{char s[SLEN];Fgets(s, SLEN-1, pFile);int n = static_cast<int>(strlen(sMagic));if (strncmp(s, sMagic, n) != 0) // check CONF file magic number    {    // truncate s at the first white space or after 20 chars    int i;    for (i = 0; i < n+1 && i < 20; i++)        if (s[i] == ' ' || s[i] == '/t' || s[i] == '/n' || s[i] == '/r')            break;    s[i] = 0;    Err("%s is not a %s config file/n"        "       First part of %s is /"%s/", expected /"%s%d/"",        sFile, sMagic, sFile, s, sMagic, CONF_FILE_VERSION);    }int nVersion;if (sscanf(s+n, "%d", &nVersion) != 1)    Err("%s has a bad header (could not read version number)", sFile);if (nVersion != CONF_FILE_VERSION)    Err("%s has a bad version number %d (expected %d)",        sFile, nVersion, CONF_FILE_VERSION);}
开发者ID:GuillaumeGibert,项目名称:swooz,代码行数:27,


示例18: str_cli

void str_cli(FILE *fp, int fd){    char readline[MAXLINE], recvline[MAXLINE];    fd_set fdset;    int max_fd;    for ( ; ; ) {        FD_ZERO(&fdset);        FD_SET(fd, &fdset);        FD_SET(fileno(fp), &fdset);        max_fd = max(fd, fileno(fp)) + 1;        select(max_fd, &fdset, NULL, NULL, NULL);                if (FD_ISSET(fd, &fdset)) {            if (Readline(fd, recvline, sizeof(recvline)) == 0) {                err_quit("str_cli: server terminated");            }            Fputs(recvline, stdout);        }        if (FD_ISSET(fileno(fp), &fdset)) {            if (Fgets(readline, sizeof(readline), fp) == NULL) {                return;            }            Writen(fd, readline, strlen(readline));        }    }}
开发者ID:cutecheng,项目名称:rounder,代码行数:28,


示例19: dg_cli

void dg_cli(FILE *fp, int sockfd, const SA *pservaddr, socklen_t servlen){	int				n;	const int		on = 1;	char			sendline[MAXLINE], recvline[MAXLINE + 1];	socklen_t		len;	struct sockaddr	*preply_addr;	preply_addr = Malloc(servlen);	Setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on)); //告诉内核广播	Signal(SIGALRM, recvfrom_alarm);	while (Fgets(sendline, MAXLINE, fp) != NULL) {		Sendto(sockfd, sendline, strlen(sendline), 0, pservaddr, servlen);		alarm(5);		for ( ; ; ) {			len = servlen;			n = recvfrom(sockfd, recvline, MAXLINE, 0, preply_addr, &len);			if (n < 0) {				if (errno == EINTR)					break;		/* waited long enough for replies */				else					err_sys("recvfrom error");			} else {				recvline[n] = 0;	/* null terminate */				printf("from %s: %s",						Sock_ntop_host(preply_addr, len), recvline);			}		}	}	free(preply_addr);}
开发者ID:feng1o,项目名称:my_unp,代码行数:30,


示例20: str_cli

void str_cli(FILE *fp, int sockfd){	int	maxfdp1;	fd_set	rset;	char	sendline[MAXLINE], recvline[MAXLINE];	FD_ZERO(&rset);	for ( ; ; ) {		FD_SET(fileno(fp), &rset);		FD_SET(sockfd, &rset);		maxfdp1 = max(fileno(fp), sockfd) + 1;		Select(maxfdp1, &rset, NULL, NULL, NULL);		if (FD_ISSET(sockfd, &rset)) { /* sockfd is readable */			if (Readline(sockfd, recvline, MAXLINE) == 0)				err_quit("str_cli: server terminated prematruely");			Fputs(recvline, stdout);		}		if (FD_ISSET(fileno(fp), &rset)) { /* input is readable */			if (Fgets(sendline, MAXLINE, fp) == NULL)				return;	/* all done */			Writen(sockfd, sendline, strlen(sendline));		}	}}
开发者ID:wuzhouhui,项目名称:unp,代码行数:26,


示例21: main

/* * main - shell main routine  */int main(int argc, char **argv) {    char cmdline[MAXLINE]; /* command line */    if (argc > 2) 	usage();    if (argc == 2) {	if (!strcmp(argv[1], "-v")) 	    verbose = 1;	else 	    usage();    }    Signal(SIGINT, sigint_handler);   /* ctrl-c */    Signal(SIGCHLD, sigchld_handler);     Signal(SIGTSTP, sigtstp_handler); /* ctrl-z */    initjobs(jobs);    /* read/eval loop */    while (1) {	/* read command line */	printf("%s", prompt);                   	Fgets(cmdline, MAXLINE, stdin); 	if (feof(stdin))	    exit(0);	/* evaluate command line */	eval(cmdline);    }     exit(0);}
开发者ID:447327642,项目名称:CSAPP2e,代码行数:36,


示例22: keyboard

void * keyboard(void * vargp) {    char buf[MAXLINE];    rio_t rio;    fprintf(stderr,"fprintf 7/n");    int clientfd = *((int*) vargp);    fprintf(stderr,"fprintf 8/n");    Rio_readinitb(&rio, clientfd);    while(Fgets(buf, MAXLINE, stdin) != NULL) {        fprintf(stderr,"fprintf 9/n");        if(active)            Rio_writen(clientfd, buf, strlen(buf));        else            break;    }    if(active) {        fprintf(stderr,"fprintf 10/n");        strcpy(buf, "$q/n");        Rio_writen(clientfd, buf, strlen(buf));    }    return NULL;}
开发者ID:pmkenned,项目名称:pimp,代码行数:28,


示例23: dg_cli

voiddg_cli(FILE *fp, int sockfd, const SA *pservaddr, socklen_t servlen){	int				n;	char			sendline[MAXLINE], recvline[MAXLINE + 1];	struct timeval	tv;	tv.tv_sec = 5;	tv.tv_usec = 0;	Setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));	while (Fgets(sendline, MAXLINE, fp) != NULL) {		Sendto(sockfd, sendline, strlen(sendline), 0, pservaddr, servlen);		n = recvfrom(sockfd, recvline, MAXLINE, 0, NULL, NULL);		if (n < 0) {			if (errno == EWOULDBLOCK) {				fprintf(stderr, "socket timeout/n");				continue;			} else				err_sys("recvfrom error");		}		recvline[n] = 0;	/* null terminate */		Fputs(recvline, stdout);	}}
开发者ID:elftech,项目名称:vmware-code,代码行数:28,


示例24: command

void command(void){    char buf[MAXLINE];    if (!Fgets(buf, MAXLINE, stdin))        exit(0);                /* EOF */    printf("%s", buf);          /* Process the input command */}
开发者ID:chengym,项目名称:csapp_dev,代码行数:7,


示例25: cat_libfile

/* cat_libfile: * Write library files onto the given file pointer. * arglib is an NULL-terminated array of char* * Each non-trivial entry should be the name of a file to be included. * stdlib is an NULL-terminated array of char* * Each of these is a line of a standard library to be included. * If any item in arglib is the empty string, the stdlib is not used. * The stdlib is printed first, if used, followed by the user libraries. * We check that for web-safe file usage. */void cat_libfile(FILE * ofp, char **arglib, char **stdlib){    FILE *fp;    char *p, **s, *bp;    int i, use_stdlib = TRUE;    /* check for empty string to turn off stdlib */    if (arglib) {	for (i = 0; use_stdlib && ((p = arglib[i])); i++) {	    if (*p == '/0')		use_stdlib = FALSE;	}    }    if (use_stdlib)	for (s = stdlib; *s; s++) {	    fputs(*s, ofp);	    fputc('/n', ofp);	}    if (arglib) {	for (i = 0; (p = arglib[i]) != 0; i++) {	    if (*p == '/0')		continue;	/* ignore empty string */	    p = safefile(p);	/* make sure filename is okay */	    if ((fp = fopen(p, "r"))) {		while ((bp = Fgets(fp)))		    fputs(bp, ofp);	    } else		agerr(AGWARN, "can't open library file %s/n", p);	}    }}
开发者ID:Goettsch,项目名称:game-editor,代码行数:41,


示例26: client

voidclient(int readid, int writeid){	size_t	len;	ssize_t	n;	char	*ptr;	struct mymesg	mesg;	/* start buffer with msqid and a blank */	snprintf(mesg.mesg_data, MAXMESGDATA, "%d ", readid);	len = strlen(mesg.mesg_data);	ptr = mesg.mesg_data + len;	/* read pathname */	Fgets(ptr, MAXMESGDATA - len, stdin);	len = strlen(mesg.mesg_data);	if (mesg.mesg_data[len-1] == '/n')		len--;				/* delete newline from fgets() */	mesg.mesg_len = len;	mesg.mesg_type = 1;	/* write msqid and pathname to server's well-known queue */	Mesg_send(writeid, &mesg);	/* read from our queue, write to standard output */	while ( (n = Mesg_recv(readid, &mesg)) > 0)		Write(STDOUT_FILENO, mesg.mesg_data, n);}
开发者ID:vonzhou,项目名称:UNPv2,代码行数:28,


示例27: dg_cli

void dg_cli(FILE* fp, int sockfd, const SA* pservaddr, socklen_t servlen){    int n;    char sendline[MAXLINE], recvline[MAXLINE + 1];    socklen_t len;    struct sockaddr* preply_addr;    preply_addr = Malloc(servlen);    Signal(SIGALRM, recvfrom_alarm);    while (Fgets(sendline, MAXLINE, fp) != NULL) {        Sendto(sockfd, sendline, strlen(sendline), 0, pservaddr, servlen);        alarm(5);        for (;;) {            if (sigsetjmp(jmpbuf, 1) != 0) break;            len = servlen;            n = Recvfrom(sockfd, recvline, MAXLINE, 0, preply_addr, &len);            recvline[n] = 0; /* null terminate */            printf("from %s: %s", Sock_ntop_host(preply_addr, servlen),                   recvline);        }    }}
开发者ID:kingfree,项目名称:haut,代码行数:25,


示例28: main

int main(int argc, char *argv[]){    int clientfd, port;    char *host, buf[MAXLINE];    rio_t rio;    /*    if(argc!= 3)    {        fprintf(stderr, "usage: %s <host> <port>/n", argv[0]);        exit(1);    }    */    //host = argv[1];    //port = atoi(argv[2]);    host ="127.0.0.1";    port=8080;    clientfd = Open_clientfd(host, port);    Rio_readinitb(&rio, clientfd);    while(Fgets(buf, MAXLINE, stdin) != NULL)    {        Rio_writen(clientfd, buf, strlen(buf));        Fputs(buf, stdout);    }    close(clientfd);    exit(0);}
开发者ID:YinWenAtBIT,项目名称:HTTP,代码行数:30,


示例29: echoClient

int echoClient(int argc, char** argv) {    int clientfd, port;    char* host, buf[MAXLINE];    rio_t rio;    if (argc != 3) {        fprintf(stderr, "usage: %s <host> <port>/n", argv[0]);        exit(0);    }    host = argv[1];    port = atoi(argv[2]);    clientfd = Open_clientfd(host, port);    Rio_readinitb(&rio, clientfd);    while (Fgets(buf, MAXLINE, stdin) != NULL) {        Rio_writen(clientfd, buf, strlen(buf));        // get response from server        Rio_readlineb(&rio, buf, MAXLINE);        //Fputs(buf, stdout);    }    Close(clientfd);    exit(0);}
开发者ID:DeathPoem,项目名称:Practice,代码行数:25,


示例30: client

void client(int readid, int writeid){	size_t len;	ssize_t n;	char *ptr;	struct mymesg mesg;	//start buffer with msqid and a blank	snprintf(mesg.mesg_data, MAXMESGDATA, "%d ", readid);	len = strlen(mesg.mesg_data);	ptr = mesg.mesg_data + len;	//read pathname	Fgets(ptr, MAXMESGDATA - len, stdin);	len = strlen(mesg.mesg_data);	if (mesg.mesg_data[len-1] == '/n')		len--;	mesg.mesg_len = len;	mesg.mesg_type = 1;	//write msqid and pathname to server well-know queue	mesg_send(writeid, &mesg);	//read from our queue, wirte to standard output	while ((n = mesg_recv(readid, &mesg)) > 0)		Write(STDOUT_FILENO, mesg.mesg_data, n);}
开发者ID:crazy-canux,项目名称:cAPI,代码行数:27,



注:本文中的Fgets函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ Fibonacci函数代码示例
C++ FeaturePcdGet函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。