- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Regarding char pointer
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-04-2006 06:11 AM
тАО10-04-2006 06:11 AM
Regarding char pointer
char *rc = NULL
short *dt;
*dt=1;
switch (*dt)
{
case 1:
rc="Intertoll"
break;
case 2:
rc="LocalExchange"
break;
case 3:
rc="other"
break;
}
Printf("%s",rc);
The output is display as "other" even when dt is 1. It should have displayed as intertoll I had pasted an sample piece of code from my application. I don't know why char pointer rc is showing an incorrect value event if dt is correct.
Dont know is there a problem with char pointer?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-04-2006 06:31 AM
тАО10-04-2006 06:31 AM
Re: Regarding char pointer
2. If it were, then "dt" would be a pointer
to nowhere. Declaring a pointer does not
create the storage to which it points.
3. If the pointer "dt" actually pointed to
some storage, then it might have worked
as you expected. That is, for example,
insert:
short dt_real; /* Allocate a short. */
dt = &dt_real; /* Point "dt" to it. */
after "short *dt;".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-04-2006 06:45 AM
тАО10-04-2006 06:45 AM
Re: Regarding char pointer
short x, *ip
x = 1;
*ip = 1; /* wrong use of pointer */
ip = &x; /* correct */
*ip = 10; /* x in now equal to 10 since *ip is the same as x */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-04-2006 07:40 PM
тАО10-04-2006 07:40 PM
Re: Regarding char pointer
char *rc = NULL
short val;
val=1;
short *dt;
dt=&val;
switch (*dt)
{
case 1:
rc="Intertoll"
break;
case 2:
rc="LocalExchange"
break;
case 3:
rc="other"
break;
}
Printf("%s",rc);
rc is not getting stored as "intertoll", it's getting stored as "other". I did a printf statement on the rc in the switch case after rc="intertoll" and it shows an incorrect value. It's going to case 1 only. Just wondering whether char pointer has some problems if we assign directly. I will try to get a snapshot from the real code after some time. I had pasted the how it appears in the real above
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-04-2006 08:40 PM
тАО10-04-2006 08:40 PM
Re: Regarding char pointer
Are you sure you'ave posted the correct script this time? Most of your statements are missing the terminating semi-colon and your Printf() starts with an uppercase "P"?
Post the complete code so that it's easier to troubleshoot.
~thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-04-2006 10:09 PM
тАО10-04-2006 10:09 PM
Re: Regarding char pointer
101 worker( swclli, a_end_clli, z_end_clli, tfuse, ttm, is_local,
102 topas_tfuse, dt_tfuse)
103 char *swclli;
104 char *a_end_clli;
105 char *z_end_clli;
106 char *tfuse;
107 char *ttm;
108 short *is_local;
109 short *topas_tfuse;
110 short *dt_tfuse;
111 {
112 int err = 0;
113 int warn = 0;
114 char *tollClli = "?";
115 char *rc = NULL;
..................
195 if (! err) switch ( *dt_tfuse ) {
196 case DT_OWN_INTERTOLL:
197 rc = "intertoll";
198 break;
199
200 case DT_OWN_LOCEX:
201 rc = "localexchange";
202 break;
203
204 case DT_OWN_NODAL:
205 rc = "nodal";
206 break;
207
208 case DT_OWN_INTL:
209 rc = "international";
210 break;
211
212 case DT_OWN_ADJUNCT:
213 rc = "adjunct";
214 break;
215
216 case DT_OWN_LOCALUSE:
217 rc = "localuse";
218 break;
219
220 case DT_OWN_OTHER:
221 rc = "other";
222 break;
223
224 default:
225 err = __LINE__;
226 break;
227 }
......
241 return rc
}
By Putting trace message i am able to observe *dt_tfuse value is DT_OWN_INTL before coming to switch..case statement. Also i had put a trace message, to display the rc value after linenumber
209 rc = "international";
The trace message shows after the execution of line number 209, rc as "other". Pls post me whether i need to paste the entire function.
The function has 240 lines so i had pasted a part of it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-04-2006 10:20 PM
тАО10-04-2006 10:20 PM
Re: Regarding char pointer
compile and run. Without line numbers. You
know, an actual program?
Even better, include the commands you used to
compile/link your test program, and an actual
transcript showing how you ran it, and what
happened when you ran it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-09-2006 05:25 AM
тАО10-09-2006 05:25 AM
Re: Regarding char pointer
1.I have niOOSdb.ec(embedded C file for query the database) in my project in which there is a function nigetOOSrptDB. I am unable to keep a breakpoint in this file. If i do a step on the function call nigetOOSrptDB in another c file it's completing the function and getting out. Is it possible to keep a break point in .ec file? Is gdb debugger allows only to keep a breakpoint in c/c++ file.
2. I am trying to display the local variable inside a function inside gdb But i dont know how to display the value of buffer in gdb. It's showing addresses if i do a (gdb) print path_n_file
$4 = {d = 0x40217658}
(gdb) bt
#0 OOSsender::process_sw_clli_det (this=0x402076d0, sw_name=@0x7b03aee8, row_acc=@0x7b03addc) at ../src/niOOSrpt.C:258
#1 0x15390 in OOSmainRpt (argc=1, input_sw=@0x7b03ad0c) at ../src/OOSrptMain.C:204
#2 0x13ee0 in main (argc=1, argv=0x7b03aac0) at ../src/OOSrptMain.C:100
(gdb) frame 0
#0 OOSsender::process_sw_clli_det (this=0x402076d0, sw_name=@0x7b03aee8, row_acc=@0x7b03addc) at ../src/niOOSrpt.C:258
258 int ret = nigetOOSrptDB ( sw_name, (long)(atoi(str_hrs)),
(gdb) info locals
ret = 0
tmp_path_n_file_sum = {d = 0x402174c8}
__R00e7 = {d = 0x40217518}
__R00e8 = {d = 0x402174c8, strung = 1 '\001'}
path_n_file = {d = 0x40217658}
__R00e2 = {d = 0x40207b28}
__R00e3 = {d = 0x40217658, strung = 1 '\001'}
__R00e4 = {d = 0x40217608}
tmp_path_n_file = {d = 0x40217568}
__R00e5 = {d = 0x402175b8}
__R00e6 = {d = 0x40217568, strung = 1 '\001'}
buffer = {d = 0x402048d8}
str_outage = {d = 0x402079e8}
str_hrs = {d = 0x40207648}
str_row = {d = 0x402048d8}
str_gaps = {d = 0x4020a060}
hrs_li = {
cacheNo = 0, index = 1, pred = 0x4020a6a8},
row_li = {
cacheNo = 0, index = 0, pred = 0x0},
gap_li = {
cacheNo = 0, index = 1, pred = 0x4020a6f8},
out_li = {
cacheNo = 0, index = 1, pred = 0x4020a718},
fp_output = (struct FILE *) 0x0
_result = 62035
int
212 OOSsender::process_sw_clli_det( const String& sw_name, long &row_acc )
213 {
214 // generate the detail trunk OOS report and push it
215 // called from from OOSmain() with one switch clli at a time.
216
217 FILE *fp_output=NULL;
218 row_acc=0; // total rows accumulated so far
219
220 DT_IN_FUNC1("OOSsender::process_sw_clli_det")
221
222 if ( dt_debug ) {
223 fprintf(stderr,"process_sw_clli_det sw_name =<%s>\n", (const char*)sw_name);
224 }
225
226 // get data from database loaded into tmp_path_n_file
227 String path_n_file = this->GETdirname() + "o" + generateJulianFileName();
228 String tmp_path_n_file = "/tmp/O" + generateJulianFileName();
229
230 String buffer;
231 String str_outage;
232 String str_hrs;
233 String str_row;
234 String str_gaps;
235 Listiter
236 Listiter
237 Listiter
238 Listiter
239 hrs_li.reset ();
240 row_li.reset ();
3. Also if there is a variable char *ptr. How do i print the value at the address pointed by ptr and address contained in the ptr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-09-2006 10:24 AM
тАО10-09-2006 10:24 AM
Re: Regarding char pointer
>print the value at the address pointed by ptr and address contained in the ptr<
~hope it helps
==============================================================
#include
int main(void)
{
char *rc;
short dt = 1, *pdt = &dt;
switch (*pdt)
{
case 1:
rc="Intertoll";
break;
case 2:
rc="LocalExchange";
break;
case 3:
rc="other";
break;
}
printf("value at address 0x%lx is %lu\n", pdt, *pdt);
printf("%s\n", rc);
}