[ create a new paste ] login | about

Link: http://codepad.org/XT0smQjN    [ raw code | fork ]

C, pasted on Nov 17:
#include <stdio.h>
#include <string.h>

char string [1024];
char *temp;
int  bola, outras;

int main (int argc, char *argv[])
{
    FILE *fp;
    register int c;

    if (argc < 2)
    {
        printf ("USAGE: %s FileName\n", argv[0]);
        return 0;
    }

    if ((fp = fopen (argv[1], "rb")) != NULL)
    {
        // zera: temp/string
        //
        temp = string;
        *temp = 0;

        while ( (c=getc(fp)) != EOF )
        {
            if (c > 32)
            {
                // EH O MESMO QUE:    string [ tamanho++ ] = c;
                //
                *temp++ = c;
            }
            else if (*string != 0)
            {
                // EH O MESMO QUE:    string [ tamanho ] = 0;
                //
                *temp = 0;

                outras++;

                // verifica a primeira letra ... caso OK, faz a comparacao.
                //
                if ((*string == 'b') && (!strcmp(string, "bola")))
                    bola++;

//                printf ("(%s)\n", string); // verifique se quiser ...

                // zera: temp/string
                //
                temp = string;
                *temp = 0;
            }
        }
        printf ("TOTAL OUTRAS: %d\n", outras);
        printf ("TOTAL BOLA: %d\n", bola);

        fclose (fp);
    }
    else printf ("File Not Found: '%s'\n", argv[1]);

    return 0;
}


Create a new paste based on this one


Comments: