Quote:
My compiler: "error". "error". "error". "[Ha ha ha, another]error".
First off, if you get compilation errors, then that is to be expected - but we can't help fix them without seeing the code and the error message(s) any more than a mechanic can fix your car if you don't let him near it with a spanner!
You should expect to get syntax errors every day, probably many times a day while you are coding - we all do regardless of how much experience we have! Sometimes, we misspell a variable, or a keyword; sometimes we forget to close a string or a code block. Sometimes the cat walks over your keyboard and types something really weird. Sometimes we just forget how many parameters a method call needs.
We all make mistakes.
And because we all do it, we all have to fix syntax errors - and it's a lot quicker to learn how and fix them yourself than to wait for someone else to fix them for you! So invest a little time in learning how to read error messages, and how to interpret your code as written in the light of what the compiler is telling you is wrong - it really is trying to be helpful!
So read this:
How to Write Code to Solve a Problem, A Beginner's Guide Part 2: Syntax Errors[
^] - it should help you next time you get a compilation error!
Quote:
I have studied this for about 3 years and I have not found anywhere in books or on the internet that tells me how to do this. Never.
Reading a byte from a file is trivial in most languages - let's take C as it's the most basic ...
1) Create a variable to refer to the file:
FILE *fp;
2) Open the file:
fp = fopen("C:\\MyFolder\\MyFile.bin", "r");
3) Create a buffer to read the byte into:
unsigned char data;
4) Read a byte:
fread(&data, 1, 1, fp);
5) Close the file:
fclose(fp);
The process is very similar in all languages: Open, read, close with appropriate variables to store data in.
Here is the whole program in C:
#include <stdio.h>
int main()
{
printf("Hello World\n");
FILE *fp;
fp = fopen("C:\\MyFolder\\MyFile.bin", "r");
unsigned char data;
printf("\"%c\"\n", data);
fread(&data, 1, 1, fp);
fclose(fp);
printf("I read one byte from the file.\nIt was \"%c\"\n", data);
return 0;
}
Inthe real world, we'd add code to check the file existed, and that it contained enough data to actually read, but that is an exercise for the reader!