Unknown symbols when I read file

Posted by Sergey Gavruk on Stack Overflow See other posts from Stack Overflow or by Sergey Gavruk
Published on 2010-03-27T16:57:33Z Indexed on 2010/03/27 17:03 UTC
Read the original article Hit count: 252

Filed under:
|

I read file, but in the end of file i get unknown symbols:

int main()
{
        char *buffer, ch;
        int i = 0, size;
        FILE *fp = fopen("file.txt", "r");
        if(!fp){
                printf("File not found!\n");
                exit(1);
        }
        fseek(fp, 0, SEEK_END);
        size = ftell(fp);
        printf("%d\n", size);
        fseek(fp, 0, SEEK_SET); 
        buffer = malloc(size * sizeof(*buffer));
        while(((ch = fgetc(fp)) != NULL) && (i <= size)){
                buffer[i++] = ch;
        }
        printf(buffer);
        fclose(fp);
        free(buffer);
        getch();
        return 0;
}

© Stack Overflow or respective owner

Related posts about c

    Related posts about file