Hi there))
I cann't deal with the file opening operation -

char* fpath = "D:\TC\myprog\readit.txt";
  FILE* fp;
fp = fopen (fpath, "r");
   if (fp != NULL) printf ("\n(!) File opennig error\n");
   else printf ("\n(+) File have been opened successfully!\n");
   for( i=0;i<=n-1;i++)
   {
     a = getc(fp);
	 putchar(a-48);
	 putchar('\n');
   }

For some reason the function does not return a NULL when the file is not in the specified location. And when he is - apparently did not read it.
Please help me understand - what's the problem.
Thank you in advance for your answers))

I have no idea what you're trying to say (what the hell is "return a book" supposed to mean?), but the file failed to open when fopen returns NULL, not the other way around. Your if statement is reversed.

yes - NULL ))) i've corrected the statement.......

fp = fopen (fpath, "r");
   if (fp == NULL) printf ("\n(!) File opennig error\n");
   else printf ("\n(+) File have been opened successfully!\n");
   for( i=0;i<=n-1;i++)
   {
     a = getc(fp);
	 putchar(a-48);
	 putchar('\n');
   }

why a file doesn't open ..... not understand.
i've attached it ->

If the file doesn't open, you can use perror to print the reason code:

if (fp == NULL)
    perror(NULL);

no such file or directory

(it said )

Then you're not opening the path you think you're opening. Consider the string: "D:\TC\myprog\readit.txt". Do you recall that escape characters start with a backslash? If you want a literal backslash, double them up: "D:\\TC\\myprog\\readit.txt". Alternatively, a forward slash also works: "D:/TC/myprog/readit.txt"

now it works ! thank you very much Narue)) as i understand - the file encoding is determinated automaticly. am i right? ))

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.