简体   繁体   English

如何从另一个函数调用字符串

[英]How to call a string from another function

This is for a school assignment where we're learning how to use functions, and I'm getting an error on the 'while' line and the fscanf line after that. 这是针对学校作业的,我们正在学习如何使用函数,而在“ while”行和此后的fscanf行上出现错误。

 <?php openFile($fin); loadFile($fin); function openFile($fin) { $fin = fopen("employees.txt", "r") or die("File not found!"); } function loadFile(&$fin) { fscanf($fin, "%s%s%f", $emp[$i][0],$emp[$i][1],$emp[$i][2]); while(!feof(&$fin)) { $i = $i + 1; fscanf($fin, "%s%s%f", $emp[$i][0],$emp[$i][1],$emp[$i][2]); } } ?> 

you should update 你应该更新

loadFile(openFile($fin));

function openFile($fin) {
    return fopen("employees.txt", "r") or die("File not found!");

}

function loadFile(&$fin) {
    fscanf($fin, "%s%s%f", $emp[$i][0],$emp[$i][1],$emp[$i][2]);
    while(!feof(&$fin)) {
        $i = $i + 1; 
        fscanf($fin, "%s%s%f", $emp[$i][0],$emp[$i][1],$emp[$i][2]);
    }
}

?>

try this add & openFile($fin) and remove & from while(!feof(&$fin)) 试试这个add&openFile($ fin)并从while(!feof(&$ fin))中删除&

openFile($fin);
loadFile($fin);

function openFile(&$fin) {
    $fin = fopen("demo.html", "r") or die("File not found!");
}

function loadFile(&$fin) {
    $i=0;
    fscanf($fin, "%s%s%f", $emp[$i][0],$emp[$i][1],$emp[$i][2]);
    while(!feof($fin)) {
        $i = $i + 1; 
        fscanf($fin, "%s%s%f", $emp[$i][0],$emp[$i][1],$emp[$i][2]);
    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM