online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
#include <string.h> #include <stdio.h> #include <stdlib.h> #define LITTLE_BUFFER_SIZE 50 /* safer_strcpy(dest, dest_end, src): copy a string into a buffer * dest: destination buffer * dest_end: past-the-end (should be dest + buffer size) * src: source string * * - returns the address of the null terminator on success * - returns NULL if the buffer is too small */ char * safer_strcpy(char *dest, char *dest_end, const char *src) { char c; do { if (dest == dest_end) { // Out of space? Bail out return NULL; } c = *src++; // Copy a character *dest++ = c; } while (c != '\0'); // Done when we copied NUL return --dest; // Back up to be on the NUL } char* checked_strcpy(char *dest, char *dest_end, const char *src) { char* cp = safer_strcpy(dest, dest_end, src); if (cp == NULL) { fprintf(stderr, "Buffer oveflow!\n"); exit(1); } } int main() { char str1[LITTLE_BUFFER_SIZE] = "Operating"; // Writeable buffer const char *str2 = "Super Systems"; // Fixed literal char str3[LITTLE_BUFFER_SIZE]; char *str4; const char *scp; char* dcp; size_t l = strlen(str1); printf("Length of str1: %zu\n", l); scp = strstr(str2, " S"); // Find some substring dcp = checked_strcpy(str1 + l, str1 + LITTLE_BUFFER_SIZE, scp); dcp = checked_strcpy(dcp, str1 + LITTLE_BUFFER_SIZE, "!!!"); dcp = checked_strcpy(dcp, str1 + LITTLE_BUFFER_SIZE, " -- Awesome."); printf("Multi-Concatenated string: %s\n", str1); checked_strcpy(str3, str3 + LITTLE_BUFFER_SIZE, str1); str3[5] = '\0'; // Shorten the string printf("First 5 characters: %s\n", str3); str4 = strdup(str3); // Make a duplicate of str3 on the heap printf("Duplicated string: %s\n", str4); free(str4); // Free the heap memory return 0; }

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