473,387 Members | 1,391 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Store printf value inside variable?

Boo
Using printf, I can get the output I want:

printf("ch:\t6%u\n",$ch);

The %u allows me to convert a negative value to an unsigned decimal
number.

My problem is that I don't want to output this to the screen. I need
to store it as a variable. Is there any way to do this? Thanks!

Jul 17 '05 #1
4 4808

Boo wrote:
Using printf, I can get the output I want:

printf("ch:\t6%u\n",$ch);

The %u allows me to convert a negative value to an unsigned decimal
number.

My problem is that I don't want to output this to the screen. I need
to store it as a variable. Is there any way to do this? Thanks!


Take a look at sprintf() <http://www.php.net/sprintf/>

Ken

Jul 17 '05 #2
Have you looked at the manual?
See also http://www.php.net/sprintf

same as printf, only returns the string

Jul 17 '05 #3
Boo wrote:
Using printf, I can get the output I want:

printf("ch:\t6%u\n",$ch);

The %u allows me to convert a negative value to an unsigned decimal
number.

My problem is that I don't want to output this to the screen. I need
to store it as a variable. Is there any way to do this? Thanks!


I'm new to PHP so can't absolutely answer your question. But, as I
understand it, PHP was designed taking ideas and methods from Perl, C++,
and various other languages. Most all have an sprintf function. Search
the manual for sprintf and I'll bet you've found exactly what you are
looking for.

--
Stan McCann "Uncle Pirate" http://stanmccann.us/pirate.html
Webmaster/Computer Center Manager, NMSU at Alamogordo
Coordinator, Tularosa Basin Chapter, ABATE of NM; AMA#758681; COBB
'94 1500 Vulcan (now wrecked) :( http://motorcyclefun.org/Dcp_2068c.jpg
A zest for living must include a willingness to die. - R.A. Heinlein
Jul 17 '05 #4
Ken Robinson wrote:
Boo wrote:
Using printf, I can get the output I want:

printf("ch:\t6%u\n",$ch);

The %u allows me to convert a negative value to an unsigned decimal
number.

My problem is that I don't want to output this to the screen. I need
to store it as a variable. Is there any way to do this? Thanks!

Take a look at sprintf() <http://www.php.net/sprintf/>

Ken


I should have read on before my initial reply, I knew there had to be an
sprintf funtion.

--
Stan McCann "Uncle Pirate" http://stanmccann.us/pirate.html
Webmaster/Computer Center Manager, NMSU at Alamogordo
Coordinator, Tularosa Basin Chapter, ABATE of NM; AMA#758681; COBB
'94 1500 Vulcan (now wrecked) :( http://motorcyclefun.org/Dcp_2068c.jpg
A zest for living must include a willingness to die. - R.A. Heinlein
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Peter Ammon | last post by:
It's my understanding that the printf() function is declared as int printf(const char * restrict format, ...); in stdio.h. And loosely speaking, if a parameter is declared as restricted, then...
188
by: infobahn | last post by:
printf("%p\n", (void *)0); /* UB, or not? Please explain your answer. */
12
by: harishg2 | last post by:
Hi, How to store a variable value for more than one executions. Ex: main() { int i=0; i++; printf("%d",i);
12
by: obdict | last post by:
Hello, I have a simple C question regarding scanf() /* What happens if user inputs a char when he/she is supposed * to input an integer? */ #include<stdio.h> int main(void){ int n;
10
by: lovecreatesbeauty | last post by:
Is parameter type conversion required for the 2nd argument on printf("%p", (void *)&i); ? But one would never call memcpy like: memcpy((void *)pi, (void *)pj, sizeof *pj); /*memcpy((void *)pi,...
34
by: Old Wolf | last post by:
Is there any possible situation for printf where %hd causes a different result to %d, and the corresponding argument was of type 'short int' ?
2
by: hikmaz | last post by:
I am trying to get the rightmost digits (%10) of a number (taken from the user) and store it into successive array locations and get rid of the rightmost digit (\10) to store the next and so on and...
13
by: pozz | last post by:
Is there some modifier that skips a parameter of a printf? For example, I pass three parameters: printf( <format string>, '-', value/10, value%10 ); In certain cases I want to print the minus...
0
by: Jens Thoms Toerring | last post by:
MN <mazouz.nezhate@gmail.comwrote: Why do you declare it as extern if you define it just two lines later?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.