السلام عليكم...
عندي مشكله عند تحرير مؤشر ل struct tm
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main(void){
int year=1990, mon=1, day=1;
struct tm* age_tm;
time_t curr_time_t, age_t;
printf("%p\n", age_tm);
time(&curr_time_t);
age_tm = localtime(&curr_time_t);
printf("%p\n", age_tm);
age_tm->tm_year = year -1900;
age_tm->tm_mon = mon-1;
age_tm->tm_mday = day;
age_t = mktime(age_tm);
age_t = curr_time_t - age_t;
if (age_t < 0){
printf("INVALID DATE ENTRED!\n");
exit(-1);
}
printf("%p\n", age_tm);
free(age_tm);
age_tm = localtime(&age_t);
printf("you have %i year(s), %i month(s) and %i day(s)\n", (age_tm->tm_year)-70, age_tm->tm_mon, age_tm->tm_mday);
return 0;
}فكيف أستطيع أن أحرر المؤشر؟؟
الناتج :
0xd2b324 0xd2e6a0 0xd2e6a0 *** glibc detected *** a.out: free(): invalid pointer: 0x00d2e6a0 *** ======= Backtrace: ========= /lib/tls/i686/cmov/libc.so.6(+0x6b591)[0xc40591] /lib/tls/i686/cmov/libc.so.6(+0x6cde8)[0xc41de8] /lib/tls/i686/cmov/libc.so.6(cfree+0x6d)[0xc44ecd] a.out[0x8048609] /lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe6)[0xbebbd6] a.out[0x8048481] ======= Memory map: ======== 0081c000-00837000 r-xp 00000000 08:07 997497 /lib/ld-2.11.1.so 00837000-00838000 r--p 0001a000 08:07 997497 /lib/ld-2.11.1.so 00838000-00839000 rw-p 0001b000 08:07 997497 /lib/ld-2.11.1.so 00bd5000-00d28000 r-xp 00000000 08:07 1022751 /lib/tls/i686/cmov/libc-2.11.1.so 00d28000-00d29000 ---p 00153000 08:07 1022751 /lib/tls/i686/cmov/libc-2.11.1.so 00d29000-00d2b000 r--p 00153000 08:07 1022751 /lib/tls/i686/cmov/libc-2.11.1.so 00d2b000-00d2c000 rw-p 00155000 08:07 1022751 /lib/tls/i686/cmov/libc-2.11.1.so 00d2c000-00d2f000 rw-p 00000000 00:00 0 00e72000-00e8f000 r-xp 00000000 08:07 997555 /lib/libgcc_s.so.1 00e8f000-00e90000 r--p 0001c000 08:07 997555 /lib/libgcc_s.so.1 00e90000-00e91000 rw-p 0001d000 08:07 997555 /lib/libgcc_s.so.1 00f5e000-00f5f000 r-xp 00000000 00:00 0 [vdso] 08048000-08049000 r-xp 00000000 08:09 1121464 /home/mhewedy/c_work/a.out 08049000-0804a000 r--p 00000000 08:09 1121464 /home/mhewedy/c_work/a.out 0804a000-0804b000 rw-p 00001000 08:09 1121464 /home/mhewedy/c_work/a.out 09962000-09983000 rw-p 00000000 00:00 0 [heap] b7700000-b7721000 rw-p 00000000 00:00 0 b7721000-b7800000 ---p 00000000 00:00 0 b78ad000-b78ae000 rw-p 00000000 00:00 0 b78c4000-b78c7000 rw-p 00000000 00:00 0 bfd52000-bfd67000 rw-p 00000000 00:00 0 [stack] Aborted

