Hi Clem
For a C program to be used the way you propose, you need to just read the standard input ‘file’.
The argc and argv values are only used to access the command line parameters
i.e. ./myCprog -v 42 would set argc to 2, and setup the argv array with argv[1] == “-v” and argv[2] == “42”
None of these are useful to you
You are trying to use your program as a ‘filter’ – it needs to read stdin, do some work, and (usually) send a result out to stdout. You can also read stdin, and that generate any other output such as write a statistic file, etc etc
The test_ascii.c program below (from a UNIX system) shows a way to read and process data from stdin. It is used like this
cat somefile.txt | ./test_ascii > invalidlinefile.txt
The cat program opens the file somefile.txt ( via argc/argv ), and writes the contents out of its’ stdout. This output is then piped into the stdin of test_ascii. The test_ascii program ignores ‘valid’ ascii characters, but will write out any input line that has an invalid character to its stdout. The > ‘diverts’ the output to a diskfile.
/*
test_ascii.c
stdin == file to be processed
stdout == lines from input with invalid ascii chars
*/
#include <stdio.h> /* define stdin/stdout etc and getline() function */
#include <stdlib.h> /* other generally useful functions */
#include <ctype.h> /* is_xxxxx() character type functions */
ssize_t getline(char ** restrict linep, size_t * restrict linecap, FILE * restrict stream);
int main()
{
FILE *fp; /* future use - open a file to write out 'clean' ascii data */
char *line = NULL;
size_t linecap = 0;
ssize_t linelen;
int i;
while ((linelen = getline(&line, &linecap, stdin)) > 0) {
for( i = 0 ; i< linelen; i++) {
if(isalpha(line[i])) { /* a-zA-Z are ok */
;
} else if(isdigit(line[i])) { /* digit is ok */
;
} else if(ispunct(line[i])) { /* punctuation is ok */
;
} else if ( line[i] == '\n') { /* linefeed is ok -- carriage return is NOT ok */
;
} else if ( line[i] == ' ') { /* simple space is ok -- tab char is NOT ok */
;
} else {
printf("--- %c %0x -------------- Error Line \n", line[i],line[i]);
fwrite(line, linelen, 1, stdout);
}
} /* end for loop */
free(line);
} /* end while */
return (0);
}
So you need to check the appropriate C idiom for the Pi C compiler (it might be slightly different to the UNIX code libraries) to enable reading the data from the ping program into the stdin of your program. It may be able to do it line by line, or might be ‘better’ character by character.
Hope this helps
Murray