Skip to content
Snippets Groups Projects
Commit 60a44e04 authored by Dong Cao's avatar Dong Cao
Browse files

first attempt on C subunit

parent f515f218
Branches
No related merge requests found
......@@ -11,4 +11,7 @@
*.mov
*.wmv
*.avi
*.avchd
\ No newline at end of file
*.avchd
# C exec files
*.ce
\ No newline at end of file
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
float take_average(int sum, int count) {
return (float)sum / (float)count;
}
int main(int argc, char *argv[]) {
FILE *inputFileHandle = NULL;
char inputFileName[128];
int value = 0;
int sum = 0;
int count = 0;
float average = 0.0;
if (argc < 2) {
printf("usage: fopen <infile>\n");
exit(1);
}
strcpy(inputFileName, argv[1]);
if ((inputFileHandle = fopen(inputFileName, "r")) == NULL) {
fprintf(stderr, "error opening file: %s\n", inputFileName);
exit(1);
}
while (fscanf(inputFileHandle, "%d", &value) != EOF) {
count++;
sum = sum + value;
}
fclose(inputFileHandle);
average = take_average(sum, count);
fprintf(stdout, "file = %s, count = %d, sum = %d, average =%8.2f\n",
inputFileName, count, sum, average);
return(0);
}
#include <stdio.h>
int main(void) {
printf("Hello World\n");
return 0;
}
8
10
2
0
5
38
1001
25
81
300
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment