파일을 스캔하고 대문자, 소문자, 숫자 또는 기타 문자가 몇 개인 지 계산합니다. 나에게 분할 오류를주는 이유가 있습니다. 왜 여기에 내 코드가 있는지 잘 모르겠습니다.
#include<stdio.h>
#include<ctype.h>
int main(void)
{
FILE *ifp, *ofp;
char *mode = "r";
char words;
int lengthOfWords, i;
int uppercase=0, lowercase=0, digits=0, other=0, total=0;
ifp = fopen("story.txt", "r");
if (ifp == NULL) {
fprintf(stderr, "Can't open input file in.list!\n");
return 0;
}
else
{
while(fscanf("%c", &words) != EOF)
{
if ((words>='A')&&(words<='Z'))
{
uppercase++;
}
else if ((words>='a')&&(words<='z'))
{
lowercase++;
}
else if ((words>='0')&&(words<='9'))
{
digits++;
}
else
{
other++;
}
}
}
printf("\n%d %d %d %d\n",uppercase, lowercase, digits, other );
return 0;
}
내가 단순히 문자별로 읽고 그들이가는대로 세는 이유
그건 그렇고 여기 내 txt 파일입니다.
The quick Fox jumps
over 2014 *$!&#@] lazy dogs.
함수 FILE
의 매개 변수로 (스트림 포인터) 를 전달하는 것을 잊었습니다 fscanf
.
while (fscanf(ifp, "%c", &words) != EOF)
남자 에 따르면 의 서명 fscanf
은 다음과 같습니다.
int fscanf(FILE *restrict stream, const char *restrict format, ...);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다