[linux-help] C help!!(out of list discussion subject)
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Hello guyz,
This question is kinda out of the list discussion but any help will be
greatly appreciated. Can anybody help me out with the following C
programming problem:
I make a structure with some char type variables:
-------------------START OF CODE------------------------------
/*POINTER TEST*/
#include <stdio.h>
//Structure Definition
struct weqaar {
char *fish;
char *sick;
};
int main(void) {
struct weqaar a; //initializing variable of type 'struct weqaar'
struct weqaar b; //initializing variable of type 'struct weqaar'
struct weqaar *ptr;
ptr=&a;
printf("\nenter value of a.fish:");
gets(a.fish);
printf("\nenter value of a.sick:");
gets(a.sick);
printf("%s\t%s",a.fish,a.sick);
printf("\n");
//checking the values stored in mem.
printf("b.fish is %s,\tb.sick is %s",b.fish,b.sick);
//
printf("\n");
printf("\nenter value of b.fish:");
gets(b.fish);
printf("\nenter value of b.sick:");
gets(b.sick);
printf("%s\t%s",b.fish,b.sick);
printf("\n");
printf("%s\t%s",a.fish,a.sick);
printf("\n");
printf("PTR values are: %s\t%s\n",ptr->fish,ptr->sick);
printf("Mem. location addresses of b.fish and b.sick are %p %p",b.fish,b.sick);
return 0;
}
-------------------END OF CODE------------------------------
Now I execute the program and store some data in the variables suppose:
I enter 'ash' in 'a.fish' and 'dish' in 'a.sick' AND 'madonna' in 'b.fish'
and 'nicole' in 'b.sick' and then terminate the program.
When I run the program again the commented line in my C prog. gives me the
output "madonna nicole", that means the values are still
there(structures being of storage type static) and my last line prints out
the memory addresses '0C5B' and 'FFF0' of variables 'b.fish' and 'b.sick'
and the program terminates exit(1). Then I note these addresses and write
another piece of code:
-------------------START OF CODE------------------------------
#include <stdio.h>
int main(void) {
char *hackPtr=0xFFF0; //note that line
printf("%s",hackPtr);
return 0;
}
-------------------END OF CODE------------------------------
now note the line 'char *hackPtr=0xFFF0;' , I have to specify 0x before the
address I got from the output of my first program, If I dont specify '0x'
the compiler takes it as a string value, my core question is how can I get
the accurate/in-the-form memory address as '0xFFF0'?? and how can I make my
other program modify the value in that location???can I read the string in
that location with my second program???or do I have to decode the value I
get(maybe HEX)???? AND how can I make structure of any non-static storage
type?????
Thanx in advance,
Weqaar Ali Janjua
BECE
Wichita State University
-- This is the linux-help@xxxxxxxxx list. To unsubscribe,
visit http://tmp2.complete.org/cgi-bin/listargate-aclug.cgi
- [linux-help] C help!!(out of list discussion subject),
Weqaar Ali Janjua <=
|
|