Code:
#include <stdio.h>

main()

{
   FILE *fp = fopen("C:test.c","rb");
   int ch;
   ch = fgetc(fp);
   rewind(fp);
   printf("%s\n",*fp);
   
   
   putchar(ch);

   
   fclose(fp);
}


this way the code works, but this way it doesn't:


Code:
#include <stdio.h>

main()

{
   FILE *fp = fopen("C:teste.c","rb");
   int ch;
 
   rewind(fp); //or fseek(fp, 0, SEEK_SET);
   printf("%s\n",*fp);
   
   
   putchar(ch);

   
   fclose(fp);
}


I read that before any operation is made on the file, like fgetc, the pointer is not pointing to the first element of the file (or something like that). does fseek count as such operation? Because it doesn't work.


Also, why is the string on the printf sucessfuly retrieved if I write *fp instead of fp, unlike other strings?
This isn't real ASM at all

What is this #include <stdio.h> include file?
Edited for privacy reasons.
Okay, I have an answer: In your second bit of code it doesn't look to me like you actually do anything with "int ch". Which probably means you keep getting a whole bunch of random data spitted back out. If you change that, it should work.

EDIT: Also, in answer to your second question, it's because you are looking at a pointer to a file stream. All the other functions take FILE *stream.

Hope this helps! Smile

EDIT2: Ephraim, what the heck are you talking about? Confused
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement