/* Author: Markus Diersbock Purpose: Peek into large files. Similar to UNIX head command if found. Created: 2001/11/10 Notes: */ #include #include #include // Functions int main(int argc, char *argv[]) { char infilename[257]; char readline[1001]; int nolinestoread; FILE *infile; int loop; if (argc != 3) { printf("\n Usage: peek \n\n"); return -1; } strcpy(infilename, argv[1]); nolinestoread=atoi(argv[2]); if (nolinestoread < 1) { printf("\nLines must be 1 or greater.\n"); return -1; } if ((infile = fopen(infilename,"r"))==NULL) { printf("\nError opening file(s)!\n\n"); return -1; } for (loop= 0 ;(!feof(infile)) && (loop <= nolinestoread); loop++) { fgets(readline,sizeof(readline),infile); printf(readline); } if (fclose(infile)==-1) { printf("\nError closing file(s)!\n\n"); return -1; } return 0; }