Last active
December 17, 2015 23:59
-
-
Save chokkan/5693789 to your computer and use it in GitHub Desktop.
A 'buggy' code for calculating the sum of values in an input file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(int argc, char *argv[]) | |
{ | |
FILE *fp = NULL; | |
double value, sum = 0; | |
fp = fopen(argv[1], "r"); | |
if (fp = NULL) { | |
fprintf(stderr, "failed to open %s\n", argv[1]); | |
return 1; | |
} | |
while (fscanf(fp, "%f", &value) == 1) { | |
sum += value; | |
} | |
printf("%f\n", sum); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment