online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
/****************************************************************************** Online C Compiler. Code, Compile, Run and Debug C program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <stdio.h> #include <string.h> #include "parsing.h" int main() { int col = 0, row = 0; char *test = "1.0,2.0;3.0,4.0;"; split_result *res1; split_result *res2; char *tmp; res1 = split_exec(test, ";"); for (int row = 0; row < split_getcount(res1); row++) { tmp = split_getvalue(res1, row); if (strlen(tmp) > 0) { res2 = split_exec(tmp, ","); for (int col = 0; col < split_getcount(res2); col++) { printf("%s\t", split_getvalue(res2, col)); } split_clear(res2); printf("\n"); } } split_clear(res1); return 0; }
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "parsing.h" split_result *split_exec(char *str, char *separator) { split_result *res = NULL; res = (split_result *)malloc(sizeof(split_result)); memset(res, 0, sizeof(split_result)); int length = strlen(str); res->buffer = malloc(length + 1); memcpy(res->buffer, str, length); res->buffer[length] = '\0'; int seplen = strlen(separator); for (int i = 0; *(str + i) != '\0'; i++) { if (strncmp(str + i, separator, seplen) == 0) { res->count++; i += (seplen - 1); } } if (res->count > 0) { res->shifts = (int *)malloc(sizeof(int) * res->count); } for (int i = 0, j = 0; *(res->buffer + i) != '\0'; i++) { if (strncmp(str + i, separator, seplen) == 0) { *(res->buffer + i) = '\0'; i += seplen - 1; *(res->shifts + j) = i + 1; j++; } } return res; } char *split_getvalue(split_result *res, int index) { static char *nan = ""; if (index > res->count) { return nan; } else if (index == 0) { return res->buffer; } else { return res->buffer + *(res->shifts + index - 1); } } int split_getcount(split_result *res) { return res->count + 1; } void split_clear(split_result *res) { free(res->buffer); if (res->shifts != NULL) { free(res->shifts); } free(res); }
#ifndef _PARSING_H_ #define _PARSING_H_ typedef struct split_result_ { char *buffer; int count; //separator count int *shifts; } split_result; split_result *split_exec(char *str, char *separator); int split_getcount(split_result *res); char *split_getvalue(split_result *res, int index); void split_clear(split_result *res); #endif

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