![]() Unfortunately, C doesn't provide a library function to output binary - you get to write it in a couple of lines. The only thing that changes is the output format you are looking at them with. Thus, one would need to generate file contents with hexadecimal data and output it as needed. Hexadecimal notation is a common format for reading binary files representing program files, encoded format, or just text. ![]() Once you have the string converted to a number, it doesn't matter whether you want to view it as decimal, hexadecimal, octal or binary, the bits in memory are the same. Use std::cout and std::hex to Convert String to Hexadecimal Value in C++. Once you have the string representation of the hexadecimal number, convert it to unsigned long with strtoul. Which brings up the point, read user-input with fgets() and you eliminate the risk of failing to nul-terminate your input string or in writing beyond you array bound (which you also fail to check). ![]() Your immediate problem is you fail to nul-terminate input in your first loop filling input and then in your second loop, you attempt to iterate until '\0' is reached - bad thing happen when you invoke Undefined Behavior. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |