Archived

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

Drakon

Easy stuff that I dont know

Recommended Posts


#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");

while(!feof(fp))
{
fread(&cTemp, sizeof(char), 1, fp);
printf("%c", cTemp);
}

fclose(fp);
getch();
return 0;
}

Share this post


Link to post
Share on other sites
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)) {
putchar(fgetc(File));
}

fclose(File);
getchar();

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