私はこれを変換するために何時間も試みてきました。charsをlongにキャストする配列をループしてみましたが、うまくいきませんでした。オンラインで簡単な例を見てきましたが、より長いchar配列のループプロセスについては説明していません。このcharの配列(SAMPLE)をlong型の1つの変数に変換するために使用できるメソッドは何ですか?
ar.h
struct ar_hdr /* file member header */
{
char ar_name[16]; /* '/' terminated file member name */
char ar_date[12]; /* file member date */
char ar_uid[6] /* file member user identification */
char ar_gid[6] /* file member group identification */
char ar_mode[8] /* file member mode (octal) */
char ar_size[10]; /* file member size */
char ar_fmag[2]; /* header trailer string */
};
私のコード
struct ar_hdr sample;
lseek(fileD, 24, SEEK_SET); //fileD is the file desriptor for the opened archive
//I start at 24 because of the 8 byte magic string for an archive starts the file "!<arch>\n"
int numRead = read(fileD, sample.ar_date, 12);
printf(sample.ar_date);
long epoch = (long *) *sample.ar_date; //terrible coding here
printf("The current time is: %s\n", asctime(gmtime(&epoch)));