online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include <stdio.h> #include <stdlib.h> int error(const char *message) { fprintf(stderr, "\nError: %s.\n", message); return EXIT_FAILURE; } void scan_string(char *buffer, unsigned length) { char format[12]; // Support max int value for the format %<num>s snprintf(format, sizeof(format), "%%%ds", length - 1); // Generate format scanf(format, buffer); } int main() { char bits[128]; printf("Enter one or more binary bits: "); scan_string(bits, sizeof(bits)); int ones = 0; for (const char *bitp = bits; *bitp != '\0'; ++bitp) { if (*bitp == '1') ++ones; else if (*bitp != '0') return error("invalid input"); } char result = (ones%2==0) ? '0' /*even*/ : '1' /*odd*/; printf("The result is: %s%c", bits, result); return EXIT_SUCCESS; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue