我需要将程序的这一部分从 C++ 转换为 C,你能帮我吗?
float ** OpenRotGrid_H(float **grid, unsigned int &nl, unsigned int & nc, bool &ok){
ifstream fs;
string line, num;
unsigned int l(0),c(0),i(0),ncmax(0);
fs.open("CarmY.txt");
if (!fs) {
//std::cout<<"Error: the Error file 'CarmY.txt' cannot be open\n\n";
ok=false;
}
else{
//size of the file
getline(fs,line);
ncmax= line.size()/MAXFLOAT;
nl++;
while(getline(fs,line)){
nl++;
}
fs.clear();
//Read CarmY values ( = grid)
grid = initialize(nl,ncmax);
fs.seekg(0,ios::beg); //initial position in the file
while(getline(fs,line)){
i=0;
c=0;
while(i<line.length()){
while(i<line.length() && line[i]!='\t'){
num.push_back(line[i]);
i++;
}
grid[l][c]=(float) atof(num.c_str());
c++;
num.clear();
if(i<line.length() && line[i]!='\n') i++;
}
l++;
}
nc=c;
fs.close();
}
return grid;
}
int main(){
unsigned int nl=0 , nc=0 , nangle=0, nrot=0;
float **grid;
bool ok;
grid=initialize(nangle, nrot);
OpenRotGrid_H(grid, nl, nc, ok);
return 0;
}
文件“C-arm”有一些不同长度的数字行,这个程序打开这个文件并取出每个数字并将其写入网格。
例如,我不知道我可以使用什么来代替getline(fs,line)
,fs.seekg
和 ...?