#include <stdio.h>
#include <stdlib.h>
int main()
{
char c;
int count = 0;
c=fgetc(file);
while (c != '\n' )
{
instruction_file[count] = atoi(c);
c = fgetc(file);
count++;
}
}
The error message is
warning: passing argument 1 of 'atoi' makes pointer from integer without a cast
/usr/include/stdlib.h 147, expected const char* but argument of type char
It looks like you are trying to use atoi
to parse single-digit numbers. However, since atoi
expects a C string and takes a const char*
, you cannot pass it a plain char
. You need to pass it a properly terminated C string:
char c[2] = {0};
c[0]=fgetc(file);
instruction_file[count] = atoi(c); // This will compile
However, this is not the most efficient way of interpreting a digit as a numeric value: you can do the same thing faster by subtracting 0
from the digit:
char c;
...
instruction_file[count] = c - '0';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With