从文件中获取信息并与X进行比较 [英] take info from file and Compare it with X

查看:77
本文介绍了从文件中获取信息并与X进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi
如何在客户端和服务器之间执行此条件?

在data.txt中,我具有这些用户名

hi
how can I do this condition between client and server

in data.txt I have these username

11
22


在server.c
中 我在main
之前写的


in server.c
I write this before main

typedef struct
{
   int    name;
}client;
client inputQ[30];


然后我从客户端收到用户名
现在我要检查此用户名是否在data.txt文件中
我的问题是
如何检查data.txt文件中的用户名?


then I receive username from client
now I want check if this username in data.txt file or not
my question is
how can I check that username in data.txt file or not

if(strcmp(buffer,inputQ[i].name)!=0)
			{
				printf("you are here");
			}
			else
			printf("you are not here");


缓冲区是我从客户端收到的

我得到了这个警告


buffer is what I received from the client

and I got this warning

warning: passing argument 2 of ''strcmp'' makes pointer from integer without a cast

推荐答案

您没有显示buffer的定义,但我假设它是charchar *的数组.无论哪种情况,结构的name字段都是int.您不能使用strcmp()来比较这两种不同的类型.

将文件中的数据存储为char或将传入的缓冲区内容转换为int.您的选择.

You did not show the definition of buffer but I assuming it is an array of char or a char *. In either event, your name field of the struct is an int. You cannot use strcmp() to compare these two dissimilar types.

Either store the data from your file as chars or convert the incoming buffer contents to an int. Your choice.

int p = atoi(buffer);
if (p == inputQ[i].name)
...


这篇关于从文件中获取信息并与X进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆