hi there!
Im completely stuck at this point and any help whatsoever would be great.
ive got 3 main problems.
- determining the number of lines in a file
- getting rid of a newline character at the end of a string
- converting a time_t variable to a string
heres the code:
any help would be greatCode:#include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <string.h> #include <time.h> typedef struct { char name[256]; u_short mode; short user_id; short group_id; off_t size; char time_last_mod[50]; } file_sig; main(int argc, char **argv) { struct stat file_info; file_sig files[3]; //** need to make the files array = to the number of filenames, that is the number of lines in the input file **// int i=0; FILE *fptr; char filename[200]; fptr = fopen(argv[1], "r"); fgets(filename, 200, fptr); //** need to get rid of the newline character at the end of filename **// while (!feof(fptr)) { stat(filename, &file_info); //** doesnt work cos of the newline character **// time (&file_info.st_mtime); files[i].name=filename; //** doesnt work cos they are incompatible data types due to newline character **// files[i].mode=file_info.st_mode; files[i].user_id=file_info.st_uid; files[i].group_id=file_info.st_gid; files[i].size=file_info.st_size; files[i].time_last_mod=ctime(&file_info.st_mtime); //** doesnt work because they are incompatible data types **// printf("\n\nFilename: %s",files[i].name); //** doesnt work due to previous errors **// printf("Protection and Filetype: %o\n", files[i].mode); printf("User ID of owner: %o\n", files[i].user_id); printf("Group ID of owner: %o\n", files[i].group_id); printf("File Size in bytes: %o\n", files[i].size); printf("Last modify time: %s\n", files[i].time_last_mod); //** doesnt work due to previous errors *// ++i; fgets(filename, 200, fptr); //** need to get rid of the newline character at the end of filename again **// } fclose(fptr); }
-Sandy



LinkBack URL
About LinkBacks



