Can't create a file and write on it

Hmmm if someone could help me.. i am trying to create a file and then write on it, but after i run the program the information i enter from keyboard will not stay saved in the file.
Here's what i have tryed:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 #include <stdio.h>
#include <stdlib.h>

int main()
{char s1[200],s2[200];
FILE *file;
file=fopen("D:\file.txt","w+");
  printf("Nume: ");
  gets(s1);
  fputs(s1,file);
  printf("\n");
  printf("Prenume :");
  gets(s2);
  fputs(s2,file);
  printf("\n");
fclose(file);
    return 0;
}
Try to open the file without specifying the directory

 
file=fopen("file.txt","w+");
Change this: "D:\file.txt" to this: "D:\\file.txt"

Note that the backslash '\' is used to denote an escape code, such as '\n' for newline, '\t' for tab and '\\' for an actual backslash character.
http://www.cplusplus.com/doc/tutorial/constants/
Topic archived. No new replies allowed.