![]() ![]() If (inFile != NULL) fclose(inFile) // close your files when you're done While((Byte = fgetc(inFile)) != EOF) // read a byte, check if EOF, "EOF" is outside the range of "char most times" Int Byte // fgetc returns int, so use an int for "Byte" and "newByte" Scanf ("?s", f1) // set max characters to read to prevent buffer overflow Printf ("Please enter file for character counting\n") ![]() He was indexing both the file and the key with a counter (i,z), I think the same counter for the file and key (i for the the file and key)Ĭhar f1 // array big enough to hold expected input In the example that he gave though, we were allocating memory with "malloc()" or "calloc()" (I thinkg it was "callock()". The professor told me that this is the encryption banks use with a longer public key (? publicly known how long it is). Far better to use fgets() instead as it gives you complete control over what is happening. Using scanf(), especially for user input, is extremely unreliable and dangerous. I suspect you are wanting to wait until you hit Return in order to end the program, but you likely have something still in the buffer after the scanf() call. Since it is very difficult to get getchar() to return 0, this will always be an infinite loop. What is the purpose of your while(c>0) loop in your main. Convention is that all caps are used for symbolic constants and struct data types. ![]() Since if you make the very common typo of using a single equals sign you have turned a logic error into a syntax error that the compiler can catch.īefore you try to open the file, print the filename out to the screen to make sure it is correct and doesn't contain extra characters such as spaces or newlines.Īlso, using all caps for a variable name is bad practice. ![]() Which sets inFile equal to NULL and then ensures that you use a NULL pointer. A very common mistake that people make, which your code as posted does not, is to use ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |