ぼるじょあがC/C++の宿題を片づけますYO! 67代目
■ このスレッドは過去ログ倉庫に格納されています
fgetsを使う場合
#include<stdio.h>
#include<string.h>
int main(){char buf[1024];int len,count=0;
while(fgets(buf,1024,stdin)!=NULL){if((len=strlen(buf))<1023){count++}else{
if(buf[strlen(buf)-1]=='\n'){count++;}}}return 0;}
使わない場合
#include<stdio.h>
int main(){int c,count=0,l=0;while((c=fgetc(stdin))!=EOF){l++;if(c=='\n'){count++;l=0;}}
if(l){count++;}return 0;}
やっぱりfgets使わない方が簡単です。
■ このスレッドは過去ログ倉庫に格納されています