online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include <stdio.h> #define MAX_DATA_POINTS 200 typedef struct { int x; int y; } Point; int main() { FILE *file = fopen("data.txt", "r"); if (file == NULL) { printf("Error opening file.\n"); return 1; } FILE *fpp = fopen("output.txt", "w"); if (fpp == NULL) { printf("Error opening file.\n"); return 1; } Point data[MAX_DATA_POINTS]; int numPoints = 0; int x, y; while (fscanf(file, "%d,%d", &x, &y) == 2) { data[numPoints].x = x; data[numPoints].y = y; numPoints++; } fclose(file); // Find the maximum x and y values int maxX = data[0].x; int maxY = data[0].y; for (int i = 1; i < numPoints; i++) { if (data[i].x > maxX) { maxX = data[i].x; } if (data[i].y < maxY) { maxY = data[i].y; } } // Scale the values to fit the console window const int consoleWidth = 50; const int consoleHeight = 20; double scaleX = (float)consoleWidth / maxX; double scaleY = (float)consoleHeight / maxY; // Create a 2D array to represent the console window char plot[consoleHeight][consoleWidth]; // Initialize the plot array with spaces for (int i = 0; i < consoleHeight; i++) { for (int j = 0; j < consoleWidth; j++) { plot[i][j] = ' '; } } // Plot the data points on the array for (int i = 0; i < numPoints; i++) { int xIndex = (int)(data[i].x * scaleX); int yIndex = (int)(data[i].y * scaleY); if (i == 0) { plot[yIndex][xIndex] = '>'; } else { plot[yIndex][xIndex] = '.'; } } // Add the rectangular border for (int i = 0; i < consoleWidth; i++) { plot[0][i] = '-'; plot[consoleHeight - 1][i] = '-'; } for (int i = 0; i < consoleHeight; i++) { plot[i][0] = '|'; plot[i][consoleWidth - 1] = '|'; } // Print the plot array for (int i = 0; i < consoleHeight; i++) { for (int j = 0; j < consoleWidth; j++) { printf("%c", plot[i][j]); fprintf(fpp, "%c", plot[i][j]); } printf("\n"); fprintf(fpp, "\n"); } fclose(fpp); return 0; }
1,0 3,-2 4,-3 5,-5 6,-7 8,-7 10,-8 11,-8 13,-8 15,-9 17,-10 18,-11 19,-12 20,-12 21,-13 23,-14 24,-16 24,-18 24,-20 24,-23 24,-26 24,-28 22,-32 21,-35 19,-39 18,-43 17,-46 15,-49 13,-51 12,-54 12,-57 12,-60 11,-63 12,-66 13,-68 14,-72 14,-77 14,-82 15,-86 15,-91 17,-95 18,-98 19,-101 21,-105 22,-108 24,-111 26,-113 28,-115 30,-117 32,-120 35,-124 38,-128 40,-132 42,-137 44,-140 47,-144 50,-147 52,-149 54,-151 54,-153 54,-154 55,-155 55,-156 55,-157 55,-160 55,-160 54,-161 54,-161 55,-159 56,-158 56,-158 56,-158 55,-158 53,-157 51,-156 48,-155 46,-154 45,-154 43,-154 41,-153 38,-152 37,-152 33,-151 29,-150 24,-150 19,-149 16,-148 12,-146 8,-143 4,-140 0,-139 -5,-137 -8,-135 -11,-134 -14,-132 -17,-130 -19,-127 -22,-124 -26,-121 -26,-121
|------------------------------------------------| | . .... .. | | . | | . . | | . . | | .. | | .. . | | .. | | ... | | . | | .. | | . . | | . | | .. . | | .. ... . . | | . . . . . . | | . . | | . . . . . | | . . . . . . . . . .| |------------------------------------------------|

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