了解C中的文件处理 [英] Understanding of file handling in C
问题描述
执行某些操作。什么是分配文件指针的语法
假设该文件位于C:\Acads\bin\File.txt。
在我的代码中,当我尝试这个
FILE * fp1;
fp1 =(C:\Acads\bin\File.txt,r +);
最终给我一个错误。
更新:
好的,这里是我的主要疑问。
编译器,我的文件位于某某路径。
我已经尝试了你们告诉我的所有事情,但无济于事。 一个错字:应该说:
pre $ fp1 = fopen(filename,r +);
另外,您必须将每个反斜线char \
与另一个反斜杠:
fp1 = fopen(C:\\Acads\\bin\\\ \\File.txt, R +);
这是因为 \
转义序列。例如: \\\
将意味着一个换行符。
\\
扩展为简单的反斜杠。
How exactly do I take an input from a file in C?
As in, for instance: Say i assigned a file pointer to a particular file and want to peform certain operations. What exactly is the syntax for assigning the file pointer Assume the file, is located at C:\Acads\bin\File.txt. In my code when I try this
FILE *fp1;
fp1=("C:\Acads\bin\File.txt","r+");
It ends up giving me an error.
UPDATE: Okay so here is my main doubt.
How exactly do i tell the compiler that my file is located at so and so path. I've tried doing everything you guys have told me but to no avail.
I think you ran into a typo: It should say:
fp1=fopen(filename,"r+");
Also you have to escape each backslash char \
with another backslash:
fp1=fopen("C:\\Acads\\bin\\File.txt","r+");
This is because the \
begins an escape sequence. E.g: \n
would mean a newline. \\
is expanded to a simple backslash.
这篇关于了解C中的文件处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!