I wrote the following code:
Code:
#include "stdafx.h"
#include "string.h"
#include "ctype.h"

int count_nonspace(const char* str)
{
    int count = 0;
    while (*str)
    {
        if (!isspace(*str++))
            count++;
    }
    return count;
}


int _tmain(int argc, _TCHAR* argv[])
{
    int a[127];
    int i = 0, j = 0, count[127] = { 0 };

    int cur_count = 1; /* Gets compared with value in count[] */
    char cur_char = '\0';
    char string[100] = "Hellooooo world";
    for (i = 0; i < strlen(string); i++)
    {
        if (cur_char == string[i])
        {
            cur_count++;
        }
        else
        {
            if (32 < cur_char && cur_char < 127)
            {
                if (cur_count > count[cur_char])
                {
                    count[cur_char] = cur_count;
                }
            }
            cur_char = string[i];
            cur_count = 1;
            if (32 < cur_char && cur_char < 127)
            {
                if (!(count[cur_char]))
                {
                    count[cur_char] = cur_count;
                }
            }
        }
    }

    /* Find the most consecutive char and print it. */
    char max_char = '\0';
    int max_count = 0;
    for (j = 0; j < 127; j++)
    {
        if (max_count < count[j])
        {
            max_count = count[j];
            max_char = j;
        }
    }
    printf("%c\n", max_char);
}
This program is checking how many times each character appears in a row but it uses string as a source of a text and i want to use a file. I am not very fluent in operating on files, thus my question is what should be change in this program to make it work on files, not only on strings?