[ create a new paste ] login | about

Link: http://codepad.org/wav0qZEj    [ raw code | output | fork ]

C, pasted on Sep 26:
#include<stdio.h>
#include<stdlib.h>

int main(int argc, char *argv[]) {
	FILE *fp;
	char line[64] = {0};
	int sum = 0;
	
	if (argc < 2) {
		return EXIT_FAILURE;
	}
	
	fp = fopen(argv[1], "r");
	while (fgets(line, 64, fp)) {
		sum += atoi(line);
	}
	fclose(fp);
	
	printf("sum is\t%d\n", sum);
	
	return EXIT_SUCCESS;
}


Output:
1
Exited: ExitFailure 1


Create a new paste based on this one


Comments: