• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ Fgets函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了Fgets函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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,代码来源:help.c


示例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,代码来源:mainopen.c


示例3: 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)) {
			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,代码来源:str.c


示例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,代码来源:19086.c


示例5: 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,代码来源:server.c


示例6: 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,代码来源:udp_brd_client.c


示例7: 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,代码来源:echoclient.c


示例8: 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);

	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,代码来源:dgcliaddr.c


示例9: 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,代码来源:client2.c


示例10: dg_cli

void
dg_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,代码来源:dgclitimeo3.c


示例11: 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,代码来源:interaction.cpp


示例12: server

void
server(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,代码来源:server.c


示例13: 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,代码来源:dg_cli02.c


示例14: 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,代码来源:dgcli01.c


示例15: 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,代码来源:server.c


示例16: command

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


示例17: CheckConfFileHeader

static void
CheckConfFileHeader (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,代码来源:readconf.cpp


示例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,代码来源:strcliselect01.c


示例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,代码来源:dgclibcast1.c


示例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,代码来源:strcliselect01.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ Fibonacci函数代码示例发布时间:2022-05-30
下一篇:
C++ FeaturePcdGet函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap