From 7188b121e0c76610c17fe7cb9b62e789dd3e73e0 Mon Sep 17 00:00:00 2001 From: Xiao Pan Date: Mon, 7 Apr 2025 15:03:30 -0700 Subject: use a constant instead for data arrary length --- remote_plot.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/remote_plot.c b/remote_plot.c index 23dc8cc..9355885 100644 --- a/remote_plot.c +++ b/remote_plot.c @@ -31,6 +31,8 @@ // like 15782 which is 7 bytes consider newline and \0? #define MAX_XFER_BUF_SIZE 7 +#define LEN 10 + // Variables for holding error return info from PLplot static PLINT pl_errcode; static char errmsg[160]; @@ -39,8 +41,8 @@ typedef struct { ssh_session session; sftp_session sftp; PLINT id1; - PLFLT t[10]; - PLFLT buffer[10]; + PLFLT t[LEN]; + PLFLT buffer[LEN]; GtkWidget *area; }DATA; @@ -67,7 +69,7 @@ static gboolean sftp_read_sync(gpointer user_data) return SSH_ERROR; } - for(int i=0;i<9;i++) + for(int i=0;i<(LEN-1);i++) data->buffer[i]=data->buffer[i+1]; for (;;) { @@ -86,7 +88,7 @@ static gboolean sftp_read_sync(gpointer user_data) //printf("id1 %d\n",data->id1); //printf("t %f\n",data->t[9]); //printf("before sftp_read_sync plstripa\n"); - data->buffer[9]=atof(buffer); + data->buffer[LEN-1]=atof(buffer); //printf("after sftp_read_sync plstripa\n"); } @@ -97,7 +99,7 @@ static gboolean sftp_read_sync(gpointer user_data) return rc; } - for(int i=0;i<10;i++) + for(int i=0;it[i]++; //printf("sftp_read_sync end\n"); @@ -297,7 +299,7 @@ static void draw_function (GtkDrawingArea *area, autoy = 0; // autoscale y acc = 1; // accumulate - for(int i=0;i<10;i++) + for(int i=0;it[i]); //printf("buffer%d %f\n",i,data->buffer[i]); @@ -314,11 +316,11 @@ static void print_data (GtkWidget *widget, gpointer user_data) { DATA *data=user_data; printf("t:"); - for(int i=0;i<10;i++) + for(int i=0;it[i]); printf("\n"); printf("buffer:"); - for(int i=0;i<10;i++) + for(int i=0;ibuffer[i]); printf("\n"); } @@ -364,7 +366,7 @@ int main (int argc, char **argv) GtkApplication *app; int status; - for(int i=0;i<10;i++) + for(int i=0;i