프로그램의 요점은 2 개의 파일, 하나의 사전과 다른 하나는 텍스트이고, 출력 파일을 만들고, 텍스트 파일에 모든 단어를 넣는 것이지만 그 단어를 대문자로 사용하는 것입니다. 사전에 존재하지 않습니다.fscanf 루프에 갇혀있다
프로그램을 실행할 때 입력 요청이 계속되어 fscanf 루프에 걸렸습니다. 그리고 난 단지 3 fscanf 루프 있습니다. 그것들 중 하나 여야합니다. 그러나 나는 왜 그리고 어떤 이유인지 알 수 없습니다.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <ctype.h>
#define wosi 20
int comp (const void *a, const void *b);
int main(int ac, char *av[])
{
int wordcount,i;
FILE *infi, *outfi;
char nothing, *dicptr, fina[100],letter[wosi];
unsigned char c;
/*to return error in case number of arguments mismatch*/
if (ac!=3)
{
fprintf (stderr," prog3: Man, I need 3 arguments to work!\n");
return (1);
}
/*first fscanf loop*/
while ((fscanf(infi,"%s",¬hing)!=0))
wordcount++;
/* end of step 2 */
dicptr = malloc(wordcount * wosi);
/* end of step 3*/
rewind(infi);
/*second fscanf loop */
for (i=0; fscanf(infi,"%s",&dicptr[i*wosi]) ;i++){}
/* this is qsort stage (finishing step 4) */
qsort (dicptr,wordcount,wosi,comp);
/*step 5 */
fclose (infi);
infi = fopen(av[2],"r");
if (infi == NULL)
{
perror("opening");
fprintf(stderr,"Can't open %s, the file is empty\n",av[2]);
return(1);
}
/*step 6 here */
strcpy(fina, av[2]);
strcat(fina, ".out");
outfi = fopen(fina, "w");
/*step 7*/
/* third fscanf loop */
while((fscanf(infi, "%s", letter)!= EOF));
{
for(i=0; letter[i]!='\0' ;i++)
{
c=letter[i];
letter[i]= toupper(c);
}
if(bsearch(letter,dicptr,wordcount,wosi,comp))
{
for(i=0;letter[i]!='\0';i++)
{
c=letter[i];
letter[i]= tolower(c);
}
}
/* fputs to print in out file*/
for(i=0; letter[i];i++)
{
fprintf(outfi,"%s",letter);
}
}
free(dicptr);
return (0);
}
int comp (const void *a, const void *b)
{
return (strcmp((const char *) a, (const char*) b));
}
http://stackoverflow.com/q/15440488/1758762 – duDE
모든 루프 앞뒤에 stderr에 마커를 인쇄하여 루프를 해결할 수 있습니까? –
인쇄 마커를 넣으려고했지만 문제는 여전히 동일합니다. –