I'm basically trying to take a file loaded with 1's and 0's like:
10101000 00000000 01010100
10000000 00000000 00000000
01101000 11111111 00000000
and take those exact boolean numbers into an array in that exact order. I don't have much experience with fscanf and general file I/O with C so its a bit rough. This is what I have so far.
#include <stdio.h>
bool memory[1024];
char file;
char bit;
int i;
int main () {
file = fopen ("memory.txt", "r");
while (fscanf (file, "%d", bit) != EOF) {
i = 0;
memory[i] = bit;
++i;
}
}
Upon my attempts at compiling this I get:
./stackexample.c:3:1: error: unknown type name ‘bool’
bool memory[1024];
^
./stackexample.c: In function ‘main’:
./stackexample.c:9:10: warning: assignment makes integer from pointer without a cast [enabled by default]
file = fopen ("memory.txt", "r");
^
./stackexample.c:10:5: warning: passing argument 1 of ‘fscanf’ makes pointer from integer without a cast [enabled by default]
while (fscanf (file, "%d", bit) != EOF) {
^
In file included from /usr/include/features.h:374:0,
from /usr/include/stdio.h:27,
from ./stackexample.c:1:
/usr/include/stdio.h:443:12: note: expected ‘struct FILE * __restrict__’ but argument is of type ‘char’
extern int __REDIRECT (fscanf, (FILE *__restrict __stream,
^
./stackexample.c:10:5: warning: format ‘%d’ expects argument of type ‘int *’, but argument 3 has type ‘int’ [-Wformat=]
while (fscanf (file, "%d", bit) != EOF) {
^
I'm not quite sure why its saying unknown type bool and I don't quite understand the warnings about making an integer from a pointer either.