First, I can't speak ENGLISH very well.. please understand :)
When I try to open text file to write something using fopen() with gvim, e.g. FILE *f = fopen("data.txt", "w");
, I can't find the data.txt file anywhere.. not only current directory but in Windows Explorer. BUT..It's working fine without the file. :|
I had doubts, So I've tried this FILE *f = fopen("c:\my\..."data.txt", "w");
Specify path, Working good!
I know that text file is stor开发者_运维技巧ed in the same folder as in execution file folder.
Of course, Other IDE is working very well.(MSVS or Dev C++) What's my problem??
(I'm using Windows7 and gvim.)
// Modification
// source code
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *f = NULL;
int name[10];
if((f = fopen("data.txt", "w")) == NULL){
printf("sorry..\n");
system("pause");
exit(1);
}
fprintf(f, "%s\n", "Dennis");
fclose(f);
if((f = fopen("data.txt", "r")) == NULL){
printf("sorry2..\n");
system("pause");
exit(1);
}
fscanf(f, "%s", name);
printf("%s\n", name);
fclose(f);
system("pause");
return 0;
} // I think it's no problem. I've tried different ways to try several times.
I will compile this -> map :! gcc % -o %<.exe (in vimrc. file) Push Cntl + F9. Vim 7.3, MingW 0.1-alpha-5. I just coding some source code, there are fopen(), fprintf() and fscanf(). When I tried to write on text file that I opened file, something was written there. but I could not see the text file. And, I tried to read the text file that I wrote file, although It was open, could not be read. Windows Explorer could not find the text file.
I can only guess, but I think your problem is that gvim doesn't change into the directory of your file.
There's an easy remedy for that: autochdir
Try to use Windows's search application, to locate your data.txt. If you started gvim from the start menu, they should be in "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Vim 7.3".
精彩评论