Here's the code:
There is more, but I've got no need to post the rest of it. It does what I want it to, it reads data from a file you specify, and then prints it on the screen. What I'd like to be able to do, is make it only accept a certain length string, since that would teach me more about strings and all, because at this point they are causing me problems!Code:int main() { FILE *in; int key; char filename[0]; printf("Enter the filename:"); scanf ("%s", &filename); if ((in = fopen(filename, "r")) == NULL) { puts("Unable to open the file"); return 0;
For instance, in the above code, before I put in "char filename[8];", thinking that if I did that, when Scanf read it, if the user put in more than 8 char's, it wouldn't accept it, you know? I'm really just curious as to how I could handle something like that, if anyone knows what I mean, and why do you have to have a value after "char" in the brackets? What if I don't know just how big I want the maximum to be? Like, "char[10]" or whatever, what if I don't know how big I want that string to be? When I define it, is there anyway to tell the compiler that I don't care what size it ends up being?
I hope I haven't made this too confusing, but I think I'm confused, lol....
thanks in advance guys