指向字符串然后返回64位计算机上的指针。 [英] pointer to string and then back to pointer on a 64 bit machine.
本文介绍了指向字符串然后返回64位计算机上的指针。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将指针地址打印到字符串缓冲区然后在64位计算机上读取它?
强制是使用字符串(char * buffer)只有。
使用%d打印时不会捕获指针的完整64位。
确实在printf和scanf中都存在%l目的?
How do I print a pointer address into a string buffer and then read it
back on a 64 bit machine ?
Compulsion is to use string (char * buffer) only.
printing with %d does not capture the full 64-bits of the pointer.
does %l exist in both printf and scanf for this purpose ?
推荐答案
atol不起作用!
它没有带回正确的值字符串缓冲区。
带有%lu的
sscanf非常好。
#include< stdio.h>
int main (){
char * p =(char *)182947876880;
char * p2;
char buf [100];
printf(" \ n \ nn");
printf(" lu =%lu \ n",p);
sprintf(buf,"%lu",p);
printf(" buf =%s \ n",buf);
p2 =(char *)atol(buf); //这条线不工作
sscanf(buf,%lu,& p2); // sscanf预期的工作
printf(" lu =%lu \ nn",p2);
if(p == p2) {
printf(" equal \ n");
}其他{
printf(" NOT equal\\\
) ;
}
printf(" \ n \ n");
}
atol does not work !
It does not bring back the correct value from the string buffer.
sscanf with %lu does it very well.
#include <stdio.h>
int main () {
char *p = (char *)182947876880;
char *p2;
char buf[100];
printf ("\n\n");
printf ("lu = %lu\n", p);
sprintf (buf, "%lu", p);
printf ("buf = %s\n", buf);
p2 = (char *)atol (buf); // THIS LINE DOES NOT WORK
sscanf (buf, "%lu", &p2); // sscanf DOES THE EXPECTED JOB
printf ("lu = %lu\n", p2);
if (p==p2) {
printf ("equal\n");
} else {
printf ("NOT equal\n");
}
printf ("\n\n");
}
let_the_best_man_win写道:
let_the_best_man_win wrote:
如何将指针地址打印到字符串缓冲区然后读取
返回64位机器?
强制是仅使用字符串(字符*缓冲区)。
使用%d打印不会捕获指针的完整64位。
为了这个目的,printf和scanf中是否存在%l?
How do I print a pointer address into a string buffer and then read it
back on a 64 bit machine ?
Compulsion is to use string (char * buffer) only.
printing with %d does not capture the full 64-bits of the pointer.
does %l exist in both printf and scanf for this purpose ?
那个''因为%d不是指针,%p是。
-
Ian Collins。
That''s because %d isn''t for pointers, %p is.
--
Ian Collins.
sscanf中是否有相应的%p?
Is there a corresponding %p in sscanf ?
这篇关于指向字符串然后返回64位计算机上的指针。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文