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

Any wrong with my for loop?

254 100+
It compiled no errors, but got warning.

warning : comparison between signed and unsigned integer expression.

how am i going to eliminate the warning part?
here is my code:
Expand|Select|Wrap|Line Numbers
  1. string f(string str){
  2.     transform(str.begin(), str.end(), str.begin(), ptr_fun(::tolower));
  3.  
  4.     for(int j=0; j< str.length(); j++)
  5.     {
  6.         if(ispunct(str[j])){
  7.         str.erase(j,1);
  8.         break;
  9.         }
  10.     }
  11.     return str;
  12. }
  13.  
thanks in advance.
Nov 23 '06 #1
2 1404
In your program j is int that is nothing but the signed int and length funtion returns unsigned int. To avoid this warning you have to make both of same type.
If you declare j as unsigned int then the warning will not come or you will have to do cast conversion of return type of length function.
Nov 23 '06 #2
Instead of:

for(int j=0; j < str.length(); j++)

write:

for(int j=0; j < (int) str.length(); j++)
Nov 23 '06 #3

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

Similar topics

0
by: Fabster | last post by:
Below is a code part I got somewhere and works fine for retrieving a version from a single file. Now I want to retrieve all .dll, .ocx and ..exe file versions from my harddisk in all directory's. I...
5
by: Fawke101 | last post by:
Hi There, I have a table with 3 rows. 1st has the table/column headers, 2nd contains the column data and the 3rd is where the loop for the SQL statement lies. I also have a JS sort function on...
3
by: Doron | last post by:
hi, getting the following error when running the script below. it seems to me that the cursor is retrieving more then one value each loop. any idea how to fix this? error: ERROR at line 10:...
51
by: WindAndWaves | last post by:
Can anyone tell me what is wrong with the goto command. I noticed it is one of those NEVER USE. I can understand that it may lead to confusing code, but I often use it like this: is this...
6
by: Niklaus | last post by:
Hi, Can someone point out what is wrong with this code ? How can i make it better optimize it. When run it gives me seg fault in linux. But windows it works fine(runs for a long time). Do we...
5
by: ken | last post by:
Hi, I have two questions the first is: in the example below how can I call an event from within a statement, such as replace Stop1 with cmdStop1 which is a button on my form? My second question...
5
by: goosen_cug | last post by:
#include <iostream> using namespace std; int fn(int a); void main(void) { cout<<"the n is "; cout<<fn(5); } int fn(int a)
2
by: babayaro | last post by:
when i am tryin to execute this file...the error below displayed..pls help me ERROR at line 29: ORA-06550: line 29, column 6: PLS-00306: wrong number or types of arguments in call to...
10
by: DavidSeck.com | last post by:
Hi, I am working with the Facebook API right now, an I have kind of a problem, but I don't know what I am doing wrong. So I have a few arrays, f.ex.: User albums: array(2) {
16
by: raylopez99 | last post by:
I am running out of printing paper trying to debug this...it has to be trivial, but I cannot figure it out--can you? Why am I not printing text, but just the initial string "howdy"? On the...
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...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.