Erhm . . . yeah, getting there.
But the variable you use in your while loop should be an int. getchar() etc all process a single character, so you'd think you'd use a char; but EOF has to be stored in an int, so an int it is. Not a char array of 100 elements.
Don't use scanf() -- that's why you have the newline-stripping code. Replace
Code:
scanf("%s", &filename);
with
Code:
fgets(filename, sizeof(filename), stdin);
For future reference, when reading strings with scanf(), you don't use an &. You use an & for every variable you can read, except strings. That's because strings are really arrays of characters and not a variable type unto themselves.
And this
Code:
fp = fopen("filename", "r");
should be
Code:
fp = fopen(filename, "r");
"home.html" and "filename" are string literals. filename by itself is a reference to the variable filename, and fopen() will be passed whatever is contained in filename.
Why not think of better names? . . .
You do realize that getchar() and putchar() use stdin and stdout -- the keyboard and the screen? To use the file, go
and
Code:
putc(character, fp);
except that you'd want to write to another file, not the one you're reading from. Come to think of it, why don't you just leave the putchar() as is right now, so you don't have to open a file to write to.