Web Development

General discussion


file not opening in C

By chaos buddha ·
I wanted to display the contents of any file on the console;so I wrote the following piece of C code:
#include<conio.h> #include<stdio.h>
int main(void)
FILE *P;int c;
if(P==NULL){puts("can't open file"); getch();return 0;};
else do{
getch();fclose(P);return 0;
PROBLEM:- I get the output "can't open file" Tried various combinations of file extensions/folders(like C:\TC\BIN\file.txt) but that didn't help....
Also I wud like to create an application using the code above so that when the file is clicked,the text goes to console.I don't wan't to create a zipped file but kindda "embed" it into code.Also such a file must not EAT RAM...

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -

by piyushkrsrivastava In reply to file not opening in C

When you give the path as C:\TC\BIN\file.txt, make sure to separate the components by "\\"; this is the escape sequence to prevent the compiler from treating the "\T" as a tab. So the Path should actually be ""C:\\TC\\BIN\\file.txt".

Related Discussions

Related Forums