Finding largest file in current directory?

I was hoping to get some assistance with this C program I am working on. The goal is to find the largest file in the current directory and then display this filename along with the filesize. What I have so far will display all the files in the current directory. But, how do I deal with "grabbing" and displaying the filesize?

So far:

#include <sys/stat.h>
#include <dirent.h>
#include <stdio.h>
#include <string.h>

void printfile(char *dir)
{
        DIR *dp;
        struct dirent *entry;
        struct stat statbuf;        

        if((dp = opendir(dir)) == NULL) {
           fprintf(stderr, "cannot open directory: %s\n", dir);
           return;

        }

        chdir(dir);
        while((entry = readdir(dp)) != NULL) {

           lstat(entry->d_name, &statbuf);

           if(S_ISREG(statbuf.st_mode)) {                
                 printf("%s\n", entry->d_name);
           }                

        }        
        closedir(dp);
}

int main()
{
        printfile(".");
        exit(0);
}

Shouldn't something like this work for filesize? It doesn't print the correct size.

 struct stat statbuffer;
struct dirent *entry;
if(S_ISREG(statbuffer.st_size){
int i = sizeof(entry->d_name);
printf("%d\n", i);}

Any help would be greatly appreciated.

You use S_ISREG on the st_mode entry just as your earlier code showed. You can't use it on anything else. Once you know you have a file, just display statbuffer.st_size. st_size is the size.

The sizeof operator just gives you the size of the variable...you can't do stuff like x=sizeof("Earth") to find out how big the Earth is.