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

Recommended Answers

All 6 Replies

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 <conio.h>

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.

share your ideas with me :D

let me try

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

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 ;)).

can you send me screenshot of this pls

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.