This topic is now archived and is closed to further replies.


Easy stuff that I dont know

Recommended Posts

griffenjam    193

#include stdio.h
#include conio.h

int main()
char filename[256];
FILE *fp;
char cTemp;

fscanf("%s", filename); //Assumes no spaces in filename

fp = fopen(filename, "rb");

fread(&cTemp, sizeof(char), 1, fp);
printf("%c", cTemp);

return 0;

Share this post

Link to post
Share on other sites
Null and Void    1088
Ouch. Normally I wouldn't entirely correct posted code, but I just have to in this situation.
#include <stdio.h>

int main(void) {
char Filename[256];
FILE *File;

scanf("%s",Filename); /* Also assumes no spaces */

File = fopen(Filename,"rt");
while(!feof(File)) {


return 0;

That code wouldn't just not work efficiently, it would crash. Of course, my code is only a little more efficient (I wanted to keep it simple) and has no error checking. It also sticks to ANSI functions.

[Resist Windows XP's Invasive Production Activation Technology!]

Edited by - Null and Void on October 17, 2001 6:07:39 PM

Share this post

Link to post
Share on other sites