Thanks Akshay!
Seems I understand sprinf() to return a string, but could you please explain this line?
suppose the input string is "A test string" from start = 3, end = 9.
Or, more specifically the part "%.*s", which I assume is for the formats. How does it work? Thanks again.
Thanks Akshay!
Seems I understand sprinf() to return a string, but could you please explain this line?
suppose the input string is "A test string" from start = 3, end = 9.
Or, more specifically the part "%.*s", which I assume is for the formats. How does it work? Thanks again.
You need to look at the man page for the printf() function. You'll see that:
is shorthand for:
without the need for the space for the intermediate format string.
This User Gave Thanks to Don Cragun For This Post:
Hi Don!
Your reply confused me more. (It seems a typo for man page for sprintf() instead of printf() function. Right?). Yes, I did look at the man page first. The closest part from the manpage of sprintf is:
Still not clear to me.
For Akshay, I am fine with the pointer moving like src+start. The difficult part is the "%.*s", which is my first time to see it, and I was thinking:
is equal to:
Is that right? But Don's line
confused me even more.
The format specification pointers and address with printf() is one of the most difficult part for me. Whenever I saw warning or error msgs like:
I panic and bang my head on the table.
Hi Don!
.....
is equal to:
Is that
....
The format specification pointers and address with printf() is one of the most difficult part for me. Whenever I saw warning or error msgs like:
I panic and bang my head on the table.
swap argument like this sprintf(dst, "%s %d", src + start,count);
Let me take one example printf("%*d", 5, 10) will result in " 10" being printed, with a total width of 5 characters, and printf("%.*s", 3, "akshay") will result in "aks" being printed.
Don's approach is not confusing me
Last edited by Akshay Hegde; 01-18-2014 at 03:58 PM..
Reason: more detail
This User Gave Thanks to Akshay Hegde For This Post:
Now I got it!
Don used a "recursion-like" style and escaped the symbol %%, that I never used before. (By the way, wish there is a book to cover those tricks/exceptions that you can't find in K&R book.)Thank you both so much!
I am struggling with the pointer to 2D-array (cf: 2D array of pointers). Can anybody help me elaborate how the pointer x moves in the memory to access the individual of y, especially the high lighted lines?
I have talked to one of the curators of the forum, but I am still not quite clear.
Here... (1 Reply)
Hi guys,
Besides the points bellow, what would best practices for scripting be ?
1) set the PATH
2) unset the current environment (set -u ?)
3) (re)set the IFS to default value - space (IFS="" <- is this correct ?)
4) check the return code for each action inside the script (cd, rsync,... (1 Reply)
if i create an array of pointers to a structure "struct node" as:
struct node *r;
and create "n" number of "linked lists" and assign it to the various struct pointers r using some function with a return type as structure pointer as:
r=multiplty(.......) /*some parameters*/
is... (2 Replies)
Hi all,
Can anyone provide help with getting the right syntax regarding array/pointers in C in the following code? Can't locate a specific example which clarifies this...
Say I declare a typedef to an array of pointers to some type...
/**
* An array of ptrs to sections
*/
typedef... (4 Replies)
If one wants to get a start address of a array or a string or a block of memory via a function, there are at least two methods to achieve it:
(1) one is to pass a pointer-to-pointer parameter, like:
int my_malloc(int size, char **pmem)
{
*pmem=(char *)malloc(size);
if(*pmem==NULL)... (11 Replies)
All ..
I am having a pointer array . And trying to store the addess into that pointer array . please see below the problem i faced
code:
int cnt1;
char *t_array;
char *f_array;
for(cnt1=0; cnt1<1000; cnt1++)
{
t_array =... (1 Reply)
void main()
{
int a={1,2,3,4,5,6,7,8,9,10};
int *p=a;
int *q=&a;
cout<<q-p+1<<endl;
}
The output is 10, how?
if we give cout<<q it will print the address, value won't print....
if we give cout<<p it will print the address, value won't print....
p has the base addr; q... (1 Reply)