whats wrong with my code? im trying to return a value from function ignition_status, its not returning. I cant see any problem in my code.
#include<stdio.h> #include<stdint.h> const char * ignition_status(); const char *ign_st; int main() { printf("%s", ignition_status(1)); return 0; } const char * ignition_status(int st) { if(st==1) { const char *ign_st="ON"; } else { const char *ign_st="OFF"; } return ign_st; } Thanks...
#includes have a filename?const char *ign_stinside theif/elseblocks. That declares a new variable. Which only exists within theif/elseblocks. What you are returning is then the globalign_stwhich has never been set. Remove thoseconst char *or declare it as a local variable outside theif/elseblock. If you do the latter then best to use a different variable name so as not to confuse it with the global definition.