1 year ago

#359281

test-img

kostuyk21

Clarification in using fsetpos() in text file

I'm trying to implement an evaluation of the arithmetic expression algorithm for my exam in C. I have a text file with the expression e.g "12 - 2 + cos(8)" in "r" mode. In "while" cycle I read 1 character and then apply switch on it. When I need to evaluate a function for example "cos" or "sin" it does the following:

case 'c':
         fgetpos(fp, &position);
         position -= 1;
         fsetpos(fp, &position);
         fgets(math_function, 4,fp);

Then I have math_function = "cos" and can work with it. But my teacher says that I can't use fsetpos because it's not secure and compares it with function fseek which can be used only on binary files. He refers to documentation, but I didn't find anything that can prove it or otherwise. How can I convince him or I am forbidden to use it in text files? Thanks in advance

c

fseek

fgetpos

0 Answers

Your Answer

Accepted video resources