• Hi guest! As you can see, the new Wizard Forums has been revived, and we are glad to have you visiting our site! However, it would be really helpful, both to you and us, if you registered on our website! Registering allows you to see all posts, and make posts yourself, which would be great if you could share your knowledge and opinions with us! You could also make posts to ask questions!

C Statistics file IO program

Joined
Sep 9, 2021
Messages
9,840
Reaction score
5,659
Awards
33
Hi all, the question is on I/O. Although File IO is used, there will still be printed messages such as a motivational string and help number.
The question is those rolling message LED displays, would I need to write an interface header file for dealing with that, or would it itself as the display just display the printed output?
Not sure how those things work.
/*
Three files exist.
Runners.dat
Returns.dat
Missing.dat
Runners - runaways data file which has names unsorted
Returns - runaways that have returned home sorted
Missing - those runaways that have not returned.
Statistics get pulled, and updated, if there is a return its name is wiped from the runners file.
For each runner, we do a bunch of stuff and then print motivational string, hotline string, and then restarts.
*/
The question is here, if I need to do anything special for rolling LED text displays.
 

akenu

Neophyte
Joined
Jan 22, 2023
Messages
47
Reaction score
109
Oh... Well, if you write it in something like Arduino C, then there is nothing else you need to do, as Arduino does contain interfaces for those scrolling displays. If this is a pure C, check whether the manufacturer of the display supplies any kind of library. Else you would have to write an interface that turns the text into the pin input on the display. Or, if you got one of those modern wi-fi ones, they usually also contain some form of REST service or other kinds of interfaces you can call from there with the help of the libcurl.
 
Joined
Sep 9, 2021
Messages
9,840
Reaction score
5,659
Awards
33
If I were to write such an interface, how is that done in C?
Post automatically merged:

What I have so far (I know, needs a lot of work, it was originally being written in bash, but decided C would be better for io interfaces.)

#include "stdio.h"
#include "stdlib.h"
#include "math.h"

Runners="RunawayData.txt"
Returns="ReturnsData.txt"
OFile="RandRStatResults.txt"

int n=0;
*fp =fopen(&Runners,"r+");

for (a=0;a!=NULL;a++)
{
fread $x;
x==sentinel?continue:break;
{
$n=$n+1;
y[$n]=$x;
}
}
fclose(&Runners);

sum=0;
i=0;
while($i<$n)
{
$i=$i+1;
$sum=$sum+$y[$i];
}

mean=$sum/$n;
j=$n/2;
if((n/2) == 0i)
then{
$median=$y;
else
$median=($y[j]+($y[j]+1));
}

$sum=0;
$i=0;

while ($i<$n)
{
$i=$i+1;
$sum=$sum+($y[$i]-$mean)/2;
variance=$sum/$n-1;
stddev=sqrrt($variance);
coeffvar=$stddev/$mean;
printf("\n%f %f $f",$n,$mean,$median);
x=pow($x,3);
printf("\n%f %f", $x[$i], $x[$n]);
printf("\n%f %f %f",$variance, $stddev, $coeffvar);
}

return 0;
Post automatically merged:

Related post at end of journal:
February is return the runaways, find the missing month. For me anyway.
Post automatically merged:

Still working on this. Working on this because a missing kid poster I saw one day, the next day the fourteen year old was found dead in the university athletic field here.
Post automatically merged:

Current code (still needs lots of work):
#include <stdio.h>
#include <stdlib.h>
#inlcude <math.h>
#include <ctype.h>
#include <string.h>
/* Pre-processor directives and includes */

/*
Purpose: This program reads two files, runaways and motivational/HelpNumbers.
The goal is to return the runaways to a SAFE environment.
Once a runaway is found, flags are updated to signal to update the returns file,
and unlink the runaway node and insert into the return list.
At that point the flags are read everything updated.
There is an interface engineers will have to create and implement.
*/

/* Abstract Data Type structure definitions */
/* Runner data and stats ADT using runners.dat file */
typedef struct Runner {
char* runner_name[40];
char* runner_age[3];
char* runner_gender[2];
char* runner_contact[20];
} runner;

/* Returns data and stats ADT using returns.dat file */
typedef struct Returns {
char* returns_name[40];
char* returns_age[3];
char* returns_gender[2];
char* returns_contact[20];
} returns;

/* Motivational messages ADT using motivation.txt file */
typedef struct Motivational
{
/* To comply with characters display size for LED text scroll devices */
char* Intro_String[40];
char* Core_Motivational_String[40];
char* List_Help_Num_String[40];
} motivational;

/* SAFE houses and mental health and DPS numbers ADT using SAFE.dat file */
typedef struct SAFENumbers {
char* SAFE_address[40];
char* SAFE_state[3];
char* SAFE_zipcode[6];
char* SAFE_contact[20];
} safenumbers;

/* FOR ENGINEERS TO IMPLEMENT -- interface for LED text scrolling devices */
typedef struct LED_Device_Interface { } LEDDevInterface;

typdef struct Histogram { } histogram;

typedef struct Statistics { } statistics;

typedef struct Set_ADT {
/*
Items are inserted and deleted, there is no inherent order in the
items in a given set. Merge_set, however does a merge-sort on the
items in the given set(s). Before any call is made to a set operation,
The set has been declared and a constructor has been applied.
The '==' and '<<' operators apply to values of ItemType.

} set_adt;
typedef struct set_adt set;

typedef struct List
{

}list_adt;
typedef struct list_adt list;

Returns="ReturnsData.txt"
OFile="RandRStatResults.txt"
Runner runaway_list(list L);
list L, runaway_list, return_list, safe_list;
set S, S1, S2, MergedSet, joinedSet;
int numSetItems;

/* Function Prototypes */
Void setMakeEmpty(set S);
boolean setIsEmpty(set S);
boolean setIsFull(set S);
int setCardinality(set S);
int setUnion(set S1,S2);
int setIntersection(set S1, S2);
int setDifference(set S1,S2);
set setStore(set S; int item);
int setDeleteItem(set S, int item);
set setCreate(set S);
set setJoin (set S, S1, S2, joinedSet);
set setMerge(set S1, S2, mergedSet);
set setPrintSet (set S);
int setDestroy(set S);
FILE* chomp_file(&filename, &mode, 256);
FILE* slurp_file(&filename, &mode, 4196);
returns runawayfound();
runner runawayreturn();
void motivational();
void` helpresources();
list return_list():
list setItem_to_Node();
void print_stats(void);
void print_histogram(returns R1, runners R2, histogram H){ }

/* Function Implementation */
set setCreate(set S) {
/* Purpose: to create a new set of runners, returns, and other structures as */
/* well as flags to signal to the reader to be updated in terms of statistics, */

}

Boolean setIsEmpty(S) { (S.numSetItems==0)?return TRUE:return FALSE; }

Boolean setIsFull(S) { (S.numSetItems==MAX_SET_ITEMS)?return TRUE:return FALSE; }

int setCardinality()
{

}

int setUnion(set S1,S2)
{
result.maxItems=MAX_SET_ITEMS;
for (i=0;i < MAX_SET_ITEMS-1;i++)
{
result.items=items || S2.items;
}
/S1=result; return S1;/
return result;
}

int setIntersection(set S1, S2)
{
result.maxItems=MAX_SET_ITEMS;
for (i=0;i < MAX_SET_ITEMS-1;i++)
{
result.items=items && setB.items;
}
return result;

}

int setDifference(set S2)
{
result.maxItems=MAX_SET_ITEMS;
for (i=0;i < MAX_SET_ITEMS-1;i++)
{
result.items=items && setB.items;
}
return result;

}

set setStore(set S; int item)
{

}

int setDeleteItem(set S, int item)
{

}

set setJoin (set S, S1, S2, joinedSet)
{

/* Purpose: to create a new set of runners, returns, and other structures as */
/* well as flags to signal to the reader to be updated in terms of statistics, */

}

set setMerge(set S1, S2, mergedSet)
{
/* Purpose: to create a new set of runners, returns, and other structures as */
/* well as flags to signal to the reader to be updated in terms of statistics, */

}

set setPrintSet (set S) { ; }
{
/* Purpose: to print exact set pointed to. */

}

int setDestroy(set S)
{
/* Purpose: to destroy exact set pointed to, then deallocate memory and return */
/* the deallocated memory back to the heap to avoid memory leaks, free pointers */
/* to avoid dangling pointer/null pointer errors. */
}

FILE* chomp_file(&filename, &mode, 256);
{
/* Purpose: to split the current exact file pointed to that has read mode enabled, */
/* and returns the exact field values specified. */

}

FILE* slurp_file(&filename, &mode, 4196);
{
/* Purpose: to read the current exact file pointed to that has read mode enabled */
/* all at once. */

}

return runawayfound(runner);
{
/* Purpose: to signal to the reader to be updated in terms of statistics, */
/* number or returns, latest found, then print motivational and help number */
/* message strings. runawayfound means that the structure node/element that */
/* the runaway node record fields now get inserted into a new return node. */
found = 1; /* found yet still lost */
returned = 0; /* found but not returned */
motivated = 1; /* found and motivated */
lost = 1; /* lost but found */
gotHelp = 1; /* runaway runner got help */
safe = 0; /* found but not returned or safe */
}

return runawayreturn(runner);
{
/* Purpose: to signal to the reader to be updated in terms of statistics, */
/* number or returns, latest found, latest returned, then print motivational */
/* and help number message strings. runawayreturn means that the structure node */
/* or element that the runaway node record fields now get inserted into a new */
/* return node. */
returned=1; /* not lost and safe */
found = 1; /* found and safe */
motivated = 1; /* motivated and got help */
GotHelp = 1; /* got help and motivated */
lost = 0; /* not lost and found */
safe = 1; /* found and safe */
}

def motivational();
{
/* Purpose: to signal to the reader to print a new motivational message and */
/* call helpresources() */be updated in terms of statistics, */
lost = 1;
motivated = 0;
Got help = 0;
Got help = 1;
Lost = 0;
print_stats();
helpresources();
}

def helpresources();
{
/* Purpose: to signal to the reader numbers that can be called toll free for */
/* help in being found, and reader to be updated in terms of statistics, */
motivated = 1;
GotHelp = 1;
motivational();
}

def return_list():
{
/* Purpose: to signal to the reader to be updated in terms of statistics, */
/* number or returns, latest found, latest returned, then print motivational */
/* and help number message strings. returnlist means that the structure node */
/* or element that the runaway node record fields now get inserted into a new */
/* return node. */
Return = Runner;
motivated =1;
GotHelp = 1;
found = 1;
safe = 1;
}

void print_stats()
{
/* Purpose: to signal to the reader to be updated in terms of statistics, */
/* number or returns, latest found, latest returned, then print motivational */
/* and help number message strings. runawayfound means that the structure node */
/* or element that the runaway node record fields now get inserted into a new */
/* return node. */
while (n = 0)
{
read x
if (x = sentinel);then
n = n+1
y[n] = x
call_sort(y,n)
sum=0
for(i=0;i <= n;i++)
{
sum = sum+y
}
mean = sum/n
j = (n/2)
if (n/2-j = 0)
{
median = y[j]
else
median = (y[j]+y[j+1])/2
}
sum = 0
for (i=0;i<=n;i++)
{
sum = sum+(y-mean)^2
}
variance = sum/n-1
std_dev = sqrt(variance)
coeff_var = std_dev/mean
printf ("\nN:%f MEAN:%f MEDIAN%f\n",&n,&mean,&median)
printf ("\n%f %f",&x[j],&x[n])
printf ("\nVARIANCE:%f STD_DEV:%f COEFF_VAR:%f\n",&variance,&std_dev,&coeff_var)
}
}

runner runaway_list():
{
/* Purpose: to signal to the reader to be updated in terms of statistics, */
/* number or returns, latest found, latest returned, then print motivational */
/* and help number message strings. runawayfound means that the structure node */
/* or element that the runaway node record fields now get inserted into a new */
/* return node. */
# Set total Runaways R = 0
R=0
# Open file for read
*fp=fopen("RunFile.dat","r+")
# Loop R through file RunFile
fseek("RunFile",0,0)
while (*fp != NULL)
do
fread("RunFile",&i)
R=R+R
# Return Runaways=R
done
# Close RunFile
fclose("RunFile")
}

def return_list():
{
/* Purpose: to signal to the reader to be updated in terms of statistics, */
/* number or returns, latest found, latest returned, then print motivational */
/* and help number message strings. runawayfound means that the structure node */
/* or element that the runaway node record fields now get inserted into a new */
/* return node. */
# Set total Returns R = 0
R=0
# Open file for read
*fp=fopen("RetFile.dat","r+")
# Loop R through file RetFile
fseek("RetFile",0,0)
while (*fp != NULL)
do
fread("RetFile",&i)
R=R+R
# Return Returns=R
done
# Close RetFile
fclose(RetFile)
}

main()
{
def return_list():
def lagrange(y,j,n){ lagrange(returns,runners,n) }
def helpresources(){ }
def runawayfound(){ }
def runawayreturn(){ }
def print_histogram(returns R1, runners R2, histogram H){ }
def motivational(){Runners="RunawayData.txt"
Returns="ReturnsData.txt"
OFile="RandRStatResults.txt"


printf("\n\nRunaways and Returns starting..");
printf("Slurping File ..");
slurp_file();
int n=0;
*fp =fopen(&Runners,"r+");
for (a=0;a!=NULL;a++)
{
fread $x;
x==sentinel?continue:break;
{
$n=$n+1;
y[$n]=$x;
}
}
fclose(&Runners);
sum=0;
i=0;
while($i<$n)
{
$i=$i+1;
$sum=$sum+$y[$i];
}
mean=$sum/$n;
j=$n/2;
if((n/2) == 0i)
then{
$median=$y;
else
$median=($y[j]+($y[j]+1));
}
$sum=0;
$i=0;
while ($i<$n)
{
$i=$i+1;
$sum=$sum+($y[$i]-$mean)/2;
variance=$sum/$n-1;
stddev=sqrrt($variance);
coeffvar=$stddev/$mean;
printf("\n%f %f $f",$n,$mean,$median);
x=pow($x,3);
printf("\n%f %f", $x[$i], $x[$n]);
printf("\n%f %f %f",$variance, $stddev, $coeffvar);
}
}

printf("Statistics run DayAndTime..");
print_stats();
print_histogram();
printf("\n\nPrinting motivaionalMessageString");
motivational();
prinf("\n\nProviding HelpNumbers...)";
help_numbers();
return 0;
}
 
Last edited:
Top