Hi I'm new in C, from this url, how do I assign the value to a variable from this printf result.
Thanks!Code:printf("The substring is: %.*s\n", j - i, &ch[i]);
Hi I'm new in C, from this url, how do I assign the value to a variable from this printf result.
Thanks!Code:printf("The substring is: %.*s\n", j - i, &ch[i]);
Maybe like this:
Code:int j; j=printf("The substring is: %.*s\n", j - i, &ch[i]);
HOPE YOU UNDERSTAND.......
By associating with wise people you will become wise yourself
It's fine to celebrate success but it is more important to heed the lessons of failure
We've got to put a lot of money into changing behavior
PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
IDE- Microsoft Visual Studio 2008 Express Edition
printf() returns the number of bytes it prints, unless there is an error. I doubt that's what you want to assign.
Looks like ch[i] is the base address of the string you want. Why not strcpy() it into some char array that you want it to go into? Lots of ways to do this.
Use sprintf() instead:
Although, you're missing a "%d" for the j-i part.Code:int i, j; char str[100]; sprintf( str, "The substring is: %.*s\n", j - i, &ch[i] );
Last edited by cpjust; 11-25-2009 at 08:11 AM.
"I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008
"the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010
HOPE YOU UNDERSTAND.......
By associating with wise people you will become wise yourself
It's fine to celebrate success but it is more important to heed the lessons of failure
We've got to put a lot of money into changing behavior
PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
IDE- Microsoft Visual Studio 2008 Express Edition
"I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008
"the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010