-
pointer casting
i have am having a problem compilng a simple memory scaning program that checks if there is anything in that address and if there is dicplays what it is this probably breaks alot of rules the way i do this but can somebody help me point out the problem here Code:
#include<stdio.h>
main(){
char *ad;
ad=1
while(*ad != 0){
printf("%d",ad);
}
printf("\n");
return 0;
}
here is the error messages(i dont know what a cast is can someone tell me?
memscan.c: In function `main':
memscan.c:6: warning: assignment makes pointer from integer without a cast
memscan.c:6: parse error before `while'
memscan.c: At top level:
memscan.c:9: parse error before string constant
memscan.c:9: warning: data definition has no type or storage class
i am running the gnu c compiler
-
i found one prblem i forgot to put a ; after my pointer assignment but i still get this error
memscan.c: In function `main':
memscan.c:5: warning: assignment makes pointer from integer without a cast
-
I saw a prior char pointer and a string literal assigned similar to
but I have never seen it declared the way that you do it.
try something like.
Code:
char *c;
char a='1';
c=&a;
I'm not even sure if this will work.
I have no compiler.
-
Such a thing requires a cast.
Code:
unsigned char *ad;
ad = (unsigned char *)1
However, while arbitrary addresses can be nonportably coerced into pointers, the chances of you using an operating system that fails to use protected mode for user level programs are slim unless you're writing embedded software. In that case you cannot point to arbitrary memory addresses and you'll need to look for another way to scan memory.