What is the STR_PTR function?

Status
Not open for further replies.

Help

Advanced Member level 2
Joined
Feb 15, 2005
Messages
617
Helped
7
Reputation
14
Reaction score
3
Trophy points
1,298
Activity points
7,065
Hi,

void PC_LINK_O_Write_String_To_Buffer(const char* const STR_PTR)
{
int i=0;

while(STR_PTR != '\0')
{
PC_LINK_O_Write_Char_To_Buffer(STR_PTR);
i++;
}
}

Anyone can help me to explain the type of function call? and
what the meaning for '\0'?

Thank You..
 

Re: Function

\0 means the NULL character. In ASCII, that is a character whose code is 0x00. It is usually used to indicate the end of a character string. A function that prints characters typically looks for this character and stops printing when it finds it, since this means the end of the string.
 

    Help

    Points: 2
    Helpful Answer Positive Rating
Function

... and STR_PTR is a const pointer to a const char. That means the function code cannot modify the pointer or the char that it points to.
 

Re: Function

echo47 said:
... and STR_PTR is a const pointer to a const char. That means the function code cannot modify the pointer or the char that it points to.

Hi,

What you mean cannot modify the pointer or the char that it points to. Please can you give some simple sample so that i can try it and i can more understand it..

So, for this function how can i declare the function prototype?

Thanks..
 

Re: Function

Here is an example of violating both const qualifiers:

Code:
void PC_LINK_O_Write_String_To_Buffer(const char* const STR_PTR)
{
  STR_PTR = 0;      // attempt to modify the pointer
  *STR_PTR = 0;     // attempt to modify what it points to
}
If I attempt to compile that in gcc, it emits errors for lines 3 and 4:
test.c: In function `PC_LINK_O_Write_String_To_Buffer':
test.c:3: error: assignment of read-only location
test.c:4: error: assignment of read-only location


The prototype for that function is simply:
void PC_LINK_O_Write_String_To_Buffer(const char* const);
 

Re: Function

echo47 said:
Code:
void PC_LINK_O_Write_String_To_Buffer(const char* const STR_PTR)
{
  STR_PTR = 0;      // attempt to modify the pointer
  *STR_PTR = 0;     // attempt to modify what it points to
}

I still not understand the "void PC.....(const char* const STR_PTR)", why they declare const char* const, what is this mean the const char* combine with const

i just know if :

char amessage[] = "hello"; // array, element will store in storage (individual character within the array may be changed)

char *pmessage = "hello"; // pmessage is initialize to point to a string constant (cannot modify the string contents)

Can you give the simple complete program for this const char* const example??

Thanks for your help....
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…