there's an error in this code... can you help me repair it?!
#include
#include
#include
#include
void initval();
int chars[255];
int main()
{
FILE *file_r;
int ferr = 0, i;
char filename[50];
while (ferr == 0)
{
system("cls");
printf("Enter file name: ");
gets(filename);
file_r = fopen(filename, "r");
if (file_r == 0)
{
printf("Error! File does not exist!");
getch();
}
else
{
ferr = 1;
}
}
char *r;
char c, ctr = 0;
while ((c = getc(file_r)) != EOF)
{
ctr++;
}
fclose(file_r);
file_r = fopen(filename, "r");
char string[ctr];
i = -1;
while ((c = getc(file_r)) != EOF)
{
i++;
string[i] = c;
}
printf("\n%s", string);
printf("\n\n%s\n\n", strrev(string));
//tig-ihap
for (i = 0; i < strlen(string); i++)
{
chars[string[i]]++;
}
for (i = 0; i < 256; i++)
{
if (chars[i] != 0)
{
printf("%c = %d\n", i, chars[i]);
}
}
getch();
fclose(file_r);
return 0;
}
void initval()
{
int i;
for (i = 0; i < 256; i++)
{
chars[i] = 0;
}
}
2007-03-20
05:20:09
·
5 answers
·
asked by
Pintoy
2