954,480 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Reading A File

Create a text file on desktop as “text.txt”,
content of file will be a single line as “FILE
ORGANIZATION AND ACCESS METHODS”. Write a
program to read from file only “ORGANIZATION”
word and print it on screen.

And i am doing that but it does not work .

#include <stdio.h>
#include <conio.h>

int main()
{
   FILE * pFile;
   char mystring [100];

   pFile = fopen ("f:\text.txt" , "r");
   if (pFile == NULL) perror ("Error opening file");
   else {
     fseek ( pFile , 6 , SEEK_SET);
     fgets (mystring , 12 , pFile);
     puts (mystring);
     fclose (pFile);
     getch();
   }
   return 0;
   
}

Any Idea ?
Thank You

nyks.up
Newbie Poster
5 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

Ya lots of ideas :

1> You could make use of code tags which would have made this post better.Read this .Or just click # on right top corner.
2> You could stop using extinct files like

And ya mainly :
3>If you are using TC and doing something like this :

fopen ("f:\text.txt" , "r");


Then you will face problems.Yoiu cannot just access any part of the file system.Just as you wish.Well if you want to try place that text file of yours inside bin of TC and try as

fopen ("text.txt" , "r");


4>More over the "\t" in your file name can cause you a problem so try "\\t" just in order to remove the special meaning of "\" within quotes.

csurfer
Posting Pro
568 posts since Jan 2009
Reputation Points: 485
Solved Threads: 88
 

share your ideas with me :D

nyks.up
Newbie Poster
5 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

let me try

nyks.up
Newbie Poster
5 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

no way doesnt work by the way i am using devc++

nyks.up
Newbie Poster
5 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 
no way doesnt work by the way i am using devc++

Ok I thought you were using TC,well even for devcpp Instructions #1,#2,#4 Hold good.

Make the change in instruction #4 of my earlier post it will work. I tried and its working fine.(If you have a file by that name in that location ;)).

csurfer
Posting Pro
568 posts since Jan 2009
Reputation Points: 485
Solved Threads: 88
 

can you send me screenshot of this pls

nyks.up
Newbie Poster
5 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You