⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 userck.m

📁 matlab book matlab book2
💻 M
字号:
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;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -