?? userck.m
字號(hào):
function found = userck(NAME)
% checks if input username exists or not
% found = 0 means I/O error
% found = 1 means user is already in list
% found = 2 means user not in list
% load and prepare file for processing
ip = fopen('userlist.txt','r');
if (ip < 0)
error('could not open file');
end;
max = 0;
nrows = 0;
s = fgetl(ip);
while(ischar(s))
nrows = nrows + 1;
if(length(s) > max)
max = length(s);
end;
s = fgetl(ip);
end;
if (length(NAME) > max)
max = length(NAME);
end;
frewind(ip);
ulist = char(zeros(nrows,max));
nrows = 0;
s = fgetl(ip);
while(ischar(s))
nrows = nrows + 1;
ulist(nrows,1:length(s)) = s;
s = fgetl(ip);
end;
fclose(ip);
% look for username
if(NAME > 0) & (nrows > 0)
% process NAME
% make all lowercase if any upper
for count = 1:length(NAME)
c = NAME(1,count);
if (('A' <= c) & (c <= 'Z'))
NAME(count) = char(abs(c) + 32);
end;
end;
% pad with zeros if smaller than longest existing name
if(length(NAME) < max)
padding = char(zeros(1,max-length(NAME)));
NAME = horzcat(NAME,padding);
end;
% compare usernames
found = 2;
for count = 1:nrows
existing = ulist(count,:);
if(NAME == existing)
found = 1;
close;
return;
end;
end;
else found = 0;
end;
return;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -