Skip to content

Instantly share code, notes, and snippets.

@Code-Hex
Created December 18, 2014 09:55
Show Gist options
  • Save Code-Hex/95cd01b3436a481e1b56 to your computer and use it in GitHub Desktop.
Save Code-Hex/95cd01b3436a481e1b56 to your computer and use it in GitHub Desktop.
7-3.c(ファイルを読み込んで、シリアルケーブルで転送する時間を表示)
#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;
}
@Code-Hex
Copy link
Author

Usage: ./7-3_/Users/../file

_ is space

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment