What is wrong in this code?Code:char buf; fgets(buf,sizeof(buf),stdin); if(buf=='1') writeBill();
What is wrong in this code?Code:char buf; fgets(buf,sizeof(buf),stdin); if(buf=='1') writeBill();
You declared buf to be a single char rather than an array of char. For storing a null terminated string, a single char can only ever store an empty string (i.e., a string with a length of 0). Also, this means that you are passing an argument of a wrong type as the first argument to fgets; your compiler should have warned you so you need to compile at a high warning level and pay attention to warnings.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)