“指针和整数”之间的比较 [英] Comparison between "Pointer and Integer"

查看:113
本文介绍了“指针和整数”之间的比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试比较IF中的指针和整数。声明


如何使这项工作?


if(patient [index] .id!= NULL){

}


谢谢

克里斯

I''m trying to compare between pointer and integer in an "IF" statement

how do I make this work?

if(patient[index].id != NULL){
}

Thanks
Chris

推荐答案

ch****@gmail.com 写道:

我正在尝试比较IF中的指针和整数。声明


如何使这项工作?


if(patient [index] .id!= NULL){

}
I''m trying to compare between pointer and integer in an "IF" statement

how do I make this work?

if(patient[index].id != NULL){
}



为什么你认为它不是?


-

Ian Collins。

Why do you think its doesn''t?

--
Ian Collins.


" ch **** @ gmail.com" < ch **** @ gmail.comwrites:
"ch****@gmail.com" <ch****@gmail.comwrites:

我正在尝试比较IF中的指针和整数。声明


如何使这项工作?


if(patient [index] .id!= NULL){

}
I''m trying to compare between pointer and integer in an "IF" statement

how do I make this work?

if(patient[index].id != NULL){
}



为什么要比较指针和整数?


什么是id ?如果它是一个指针,上面应该工作。如果它是一个

整数,将它与NULL进行比较是没有意义的。


发布一个小的,完整的程序说明是有帮助的你的

问题。如果你有一个编译程序,请告诉我们你的编译器给你的确切的

错误信息。另外,你的样本应该可以单独编译。


-

Keith Thompson(The_Other_Keith) ks *** @ mib.org < http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< *< http://users.sdsc.edu/~kst>

"我们必须做点什么。这是事情。因此,我们必须这样做。

- Antony Jay和Jonathan Lynn,是部长

Why would you want to compare a pointer and an integer?

What is "id"? If it''s a pointer, the above should work. If it''s an
integer, comparing it to NULL makes no sense.

It''s helpful to post a small, complete program that illustrates your
problem. If you''re having a compilation program, show us the exact
error message your compiler gives you. Otherise, your sample should
be compilable by itself.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"


5月27日,22日:45,Keith Thompson< k ... @ mib.orgwrote:
On 27 May, 22:45, Keith Thompson <k...@mib.orgwrote:

" chu ... @ gmail.com" < chu ... @ gmail.comwrites:
"chu...@gmail.com" <chu...@gmail.comwrites:

我正在尝试比较IF中的指针和整数。声明
I''m trying to compare between pointer and integer in an "IF" statement


如何使这项工作?
how do I make this work?


if(patient [index] .id!= NULL){

}
if(patient[index].id != NULL){
}



为什么要比较指针和整数?


什么是id?如果它是一个指针,上面应该工作。如果它是一个

整数,将它与NULL进行比较是没有意义的。


发布一个小的,完整的程序说明是有帮助的你的

问题。如果你有一个编译程序,请告诉我们你的编译器给你的确切的

错误信息。另外,你的样本应该可以自行编译。


-

Keith Thompson(The_Other_Keith)k ... @ mib.org< http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< *< http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。

- Antony Jay和Jonathan Lynn,是部长


Why would you want to compare a pointer and an integer?

What is "id"? If it''s a pointer, the above should work. If it''s an
integer, comparing it to NULL makes no sense.

It''s helpful to post a small, complete program that illustrates your
problem. If you''re having a compilation program, show us the exact
error message your compiler gives you. Otherise, your sample should
be compilable by itself.

--
Keith Thompson (The_Other_Keith) k...@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"



ok ..


#include< stdio.h>

#include< ; stdlib.h>

#include< time.h>

#include< string.h>


#定义MAXPATIENTS 20

struct details {

int id;

char forename [20];

char initial;

char surname [20];

int day_of_entry;

int max_wait;

};


//列出个别患者信息 - 正在进行工作

int list_patient(int index){

int time_left = 0;

int x = 0;

int i;


//应检查索引是否指向记录,

//否则它应该返回-1 !!

if(patient [index] .id!= NULL){

printf(" Patient)详情:\ n");

printf(" ID:%d |",patient [index] .id);

printf(" Name: %s",patient [index] .forename);

printf("%c",patient [index] .in itial);

printf("%s |",patient [index] .surname);

printf(" Days on queue%d |", day_now() - 患者[指数] .day_of_entry);

printf(最长等待天数%d \ n,time_left =

患者[指数] .max_wait - (day_now() - patient [i] .day_of_entry));

}

else {

x = -1;

}

返回x;

}


int main(无效){

list_patient(0);

返回0;

}

ok..

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

#define MAXPATIENTS 20

struct details {
int id;
char forename[20];
char initial;
char surname[20];
int day_of_entry;
int max_wait;
};

//Lists individual patient information -Work in Progress
int list_patient(int index){
int time_left = 0;
int x = 0;
int i;

//Should check if index points to a record,
//Or else it should return -1!!
if( patient[index].id != NULL){
printf("Patient Details: \n");
printf("ID: %d |",patient[index].id);
printf("Name: %s ",patient[index].forename);
printf("%c ",patient[index].initial);
printf("%s |",patient[index].surname);
printf("Days on queue %d |",day_now()- patient[index].day_of_entry);
printf("Maximum waiting days %d \n",time_left =
patient[index].max_wait - (day_now() - patient[i].day_of_entry));
}
else {
x = -1;
}
return x;
}

int main(void){
list_patient(0);
return 0;
}


这篇关于“指针和整数”之间的比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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