主题:请教如何判断字符型数组中无值
lee1985
[专家分:0] 发布于 2010-11-18 17:20:00
以一个1维长度6的字符数组为例
character(len=6)::a(100)
需要判断当中某些位置无值应该如何判断
if用0和用空格都不对,应该如何判断或者该怎么做?
谢谢
回复列表 (共26个回复)
11 楼
dongyuanxun [专家分:7180] 发布于 2010-11-19 19:54:00
[quote]As far as I know, Null Value .ne. Blank.[/quote]
No,没初始化全是\000之类啥的
12 楼
lee1985 [专家分:0] 发布于 2010-11-19 19:55:00
可能是我的表达有错,我说的是没有值的意思
请问如何判断一个字符型数组某一行有几列
13 楼
asymptotic [专家分:16630] 发布于 2010-11-19 20:32:00
There is no way to determine a variable has a value, the compiler can't help you to do this. Your problem should be initialization, it's the programmer responsibility.
Null Value not equal Blank, why do 11# say no.
14 楼
lee1985 [专家分:0] 发布于 2010-11-19 20:35:00
C can do this program
if there's no value,you can judge "null"
i think fortran can do it too.
so i will find another way
15 楼
asymptotic [专家分:16630] 发布于 2010-11-19 20:39:00
For a character array, for example
character(len = 10):: CS(3)
every CS(i) has len = 10, what is the column your mean?
Novice is just novice, you must specification your problem first.
16 楼
lee1985 [专家分:0] 发布于 2010-11-19 20:47:00
i mean
the character array CS(3)
the CS(1) and CS(2) have value but CS(3) is null
so how can i do judgement CS(3) don't have value
17 楼
asymptotic [专家分:16630] 发布于 2010-11-19 20:50:00
16# no way
18 楼
lee1985 [专家分:0] 发布于 2010-11-19 20:53:00
thank you,i will find another way to do my program
19 楼
asymptotic [专家分:16630] 发布于 2010-11-19 20:56:00
Null Value in Fortran, as far as I known, only appear I/O List-Item, which means -- not change the variable status.
20 楼
dongyuanxun [专家分:7180] 发布于 2010-11-19 21:59:00
非要用Null值的话,也不是不可以,只能用Fortran2003的ISO_C_BINDING内置module里的c_null_char,
比如
program main
use iso_c_binding
implicit none
character :: s
if(s==c_null_char) then
print *, "s is NULL"
endif
stop
end program main
我来回复