473,385 Members | 1,983 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,385 software developers and data experts.

Keep % sign using sprintf()

code green
1,726 Expert 1GB
I use %s as placeholders in a text file and something like
Expand|Select|Wrap|Line Numbers
  1. $line = sprintf(fgets($fp),$tc,$tc);
To read a line.
So $tc will replace %s in $line.

But if line contains "charge a 2% surcharge" then $tc also replaces the '%'.

How do I get round this and leave '%' untouched and only replace '%s'?
Tried backslash, that doesn't work
Jul 7 '11 #1
1 1669
code green
1,726 Expert 1GB
Solved. It is escaped with a double percent like so '%%'
Jul 7 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Venkat Venkataraju | last post by:
Hi All I'm having problems printing a string with a % char. Here is the code line = sprintf("<table width=100% id=%s>\n", $table_id); I'm getting an not enough parameter error. The % for the...
3
by: jt | last post by:
Here is my code: unsigned long listenip; short tlen; sprintf(tmp,"len:%x listenip:%x",htonl(tlen),listenip); If the value on "tlen" is less than 2 bytes and the value on "listenip" is...
12
by: babak | last post by:
Hi everyone I want to format a string (using sprintf) and put it in a messagebox but however I try to do it, it doesn't seem to work. Here is an example sample of what i try to do: char msg;...
7
by: wenmang | last post by:
what is format for sprintf to convert long long integer (64 bits) to string?
3
by: Susan Rice | last post by:
How can I rewrite this code to avoid the possibility of a buffer overflow? sprintf(errbuf, "%s\nError is: %u: %s\n", errmsg, dwErrCode, s ); Here: errmsg = a string dwErrCode = a number s =...
7
by: markww | last post by:
Hi, Is there a way to use sprintf() to put a number of zeros before a number, like: sprintf(szBuffer, "%i", 7); "007"; I have a list of numbers I want to sort that are text based, and I...
3
by: jannlin | last post by:
I have a need to print 64 bit integer in Windows and UNIX environments. Code Snipet: unsigned __int64 mNumRowsRead=1234567890123456; sprintf(buf, "%d row(s) read", mNumRowsRead); ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.