online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include <stdio.h> #include <stdlib.h> #include <string.h> char * swap(const char* vs char*); int main(void) { char s[200]; int count = 0, i; printf("Enter the string:\n"); scanf("%[^\n]s", s); for (i = 0;s[i] != '\0';i++) { if (s[i] == ' ' && s[i+1] != ' ') count++; } printf("words: %d\n", count + 1); printf("%s\n", swap(s)); } char * swap(char * s) { const size_t length = strlen(s); char * ch = malloc(length + 1); strncat(ch, s, length); ch[length] = '\0'; char * k = ch; while (k != NULL) { char * last = strchr(k, ' '); if (last != NULL) { char t = *k; *k = *(last - 1); *(last - 1) = t; k = last + 1; } else { char t = *(k); *k = *(ch + length - 1); *(ch + length - 1) = t; k = NULL; } } return ch; }

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