473,386 Members | 1,720 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,386 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 1403
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...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.