Created
December 18, 2014 09:55
-
-
Save Code-Hex/95cd01b3436a481e1b56 to your computer and use it in GitHub Desktop.
7-3.c(ファイルを読み込んで、シリアルケーブルで転送する時間を表示)
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> | |
#include <stdlib.h> | |
#include <string.h> | |
#define N 100000 | |
int main(int argc, char const *argv[]) | |
{ | |
FILE *file; | |
char buf[N]; | |
int count = 0; | |
double byte = 960; | |
double times; | |
file = fopen(argv[1], "r"); | |
if(argc > 2) exit(1); // Error Filter | |
else if(!file) exit(1); | |
while(fgets(buf, sizeof(buf), file)){ | |
strtok(buf, "\n\0"); | |
count += strlen(buf); | |
} | |
times = count / byte; | |
printf("シリアルケーブルで\n"); | |
printf("%sを送信するかかる時間は\n",argv[1]); | |
printf("%lf秒かかります。\n", times); | |
fclose(file); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: ./7-3_/Users/../file
_ is space