Liczba znaków komentarzy w pliku (programowanie C)
Wydaje mi się, że nie rozumiem tego dobrze, próbowałem wszystkiego, ale ..
int commentChars() {
char str[256], fileName[256];
FILE *fp;
int i;
do{
long commentCount=0;
fflush(stdin);
printf("%s\nEnter the name of the file in %s/", p, dir);
gets(fileName);
if(!(fp=fopen(fileName, "r"))) {
printf("Error! File not found, try again");
return 0;
}
while(!feof(fp)) {
fgets(str,sizeof str,fp);
for(int i=0;i<=sizeof str;i++) {
if(str[i] == '/' && str[i+1] == '/') {
commentCount += (strlen(str)-2);
}
}
}
fclose(fp);
printf("All the chars, contained in a comment: %ld\n", commentCount);
puts(p);
printf("Do you want to search for another file?<Y/N>: ");
i=checker();
}while(i);}
Rezultatem jest „Wszystkie znaki, kontemplowane w komentarzu: 0”, mimo że mam komentarze. Moje drugie pytanie brzmiało ... Analogicznie, jak mogę zrobić to samo w przypadku komentarzy zawierających / * * /, wydaje mi się to niemożliwe.