Reputation: 859
I am trying to read a key hit and then stop a code. In C.
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
bool starting()
{
char c;
if (kbhit())
{
c=getch();
if (c=="S"||c=="s")
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
int main()
{
while(!starting)
{
printf("line 1");
delay(100);
}
return 0;
}
Without stdbool.h
, it says errors like
syntax error: identifier 'starting',
syntax error: ";"
syntax error: ")"
'starting': undeclared identifier
With stdbool.h, it says file not found. My compiler is the one that comes with Visual Studio 2010.
Any suggestion how to remove this? How can I still use a function that returns a boolean value?
ADDED sorry! for the short comment added. resolved mostly. Thanks all
Added More Errors: After Compiling: it reads:
filename.obj unresolved external symbol _delay referenced in function _main.
What should I do?
Upvotes: 2
Views: 7240
Reputation: 122383
stdbool.h
is introduced in C99
, and Visual Studio doesn't support C99
. You can define the types yourself. One possible way is:
typedef int bool;
#define true 1
#define false 0
Upvotes: 6
Reputation: 36487
Three problems at once:
bool
as a type of its own, but you can define it (e.g. through stdbool.h
or just by using a typedef
to any other integral type (usually unsigned char
or int
; this might be a question of memory usage vs. performance based).std**.h
headers, especially older versions. So you most likely just don't have stdbool.h
in VS 2010 (the reason for the file not found error).while(!starting)
.Upvotes: -1