关于上标运算符和用指针加偏移量访问的区别
关于下标运算符和用指针加偏移量访问的区别
RT,部分代码如下所示:
求大牛给小弟一点提示。
------解决方案--------------------
printf("%s ",pshstr+shdr[i].sh_name );//使用下标pshstr[shdr[i].sh_name]就会出现段错误
printf("%s ",&pshstr[shdr[i].sh_name] );//使用下标pshstr[shdr[i].sh_name]就会出现段错误
RT,部分代码如下所示:
- C/C++ code
//analysis the shstrtab offset in the file ioffset = shdr[phead->e_shstrndx].sh_offset; isize = shdr[phead->e_shstrndx].sh_size; pshstr = (char*)malloc(sizeof(char)*isize); //read the shstrtable from file if( 0 != fseek(p,ioffset,SEEK_SET) ) { printf("move the offset for shstrtab failed!\n"); } iRet = fread(pshstr,isize,1,p); if( 1 != iRet ) { printf("read the shstrtab from file failed!\n"); } printf("The Section of Elf file: %d\n",phead->e_shnum ); printf("Index Name size offset \n"); for( i = 1; i< phead->e_shnum ; ++i ) { printf("%d ", i); printf("%s ",pshstr+shdr[i].sh_name );//使用下标pshstr[shdr[i].sh_name]就会出现段错误 printf("%d ",shdr[i].sh_size); printf("%d ",shdr[i].sh_offset); printf("\n"); }
求大牛给小弟一点提示。
------解决方案--------------------
printf("%s ",pshstr+shdr[i].sh_name );//使用下标pshstr[shdr[i].sh_name]就会出现段错误
printf("%s ",&pshstr[shdr[i].sh_name] );//使用下标pshstr[shdr[i].sh_name]就会出现段错误