Click here to Skip to main content
15,888,282 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Objective-C
#include<stdio.h>
#include<string.h>
int main()
{
char str[100]={0};
char str1[100]={0};
char *p = NULL;
puts("enter a string");
fgets(str,sizeof(str),stdin);
puts("enter substring");
fgets(str1,sizeof(str1),stdin);
p=strstr(str,str1);
if(p)
puts("sub string is a part of main string");
if(!p)
puts("sub string is  not a part of main string");
return 0;
}


I know I can get the address of variables str,str1 using p &str, p &str1 respectively. But how can I get gdb to show me the address of the puts()?
Posted
Updated 20-Jul-14 8:37am
v2
Comments
Kornfeld Eliyahu Peter 20-Jul-14 15:22pm    
Can you tell as what for do you need the address of puts() function?
Jeevan83 21-Jul-14 1:27am    
Of course I will :). There is this idiotic sir in my coaching classes. He wants every student to write a program as well as address of every line(how they are allocated in the stack) in the code in comments. I want to die! He wants us to write activation records too! But I do not know if this is correct or not because, for str and str1 it is not allocating 100 bytes each. also I am not sure how it is allocating memory both for variables and functions. Guys what do you think? Is this a good practice in any way and is this the correct way to achieve it? @Kornfeld Eliyahu Peter
Sergey Alexandrovich Kryukov 20-Jul-14 21:08pm    
Why?
—SA
Jeevan83 21-Jul-14 1:27am    
Of course I will :). There is this idiotic sir in my coaching classes. He wants every student to write a program as well as address of every line(how they are allocated in the stack) in the code in comments. I want to die! He wants us to write activation records too! But I do not know if this is correct or not because, for str and str1 it is not allocating 100 bytes each. also I am not sure how it is allocating memory both for variables and functions. Guys what do you think? Is this a good practice in any way and is this the correct way to achieve it? @Sergey Alexandrovich Kryukov
Jeevan83 21-Jul-14 14:13pm    
reply please guys!!!!!

1 solution

You can use
C++
#include <stdio.h>

//...

int (_cdecl * fpointer)(const char*) = &puts;
// where int (_cdecl * fpointer)(const char*) declares the variable "fpointer"
// of the type "pointer to the function accepting one argument of the type "const ''char*"
// and returning int"

// or even

void* address = &puts;


But why?

Please see, for example: http://www.cprogramming.com/tutorial/function-pointers.html[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900