473,387 Members | 1,423 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.

what is wrong need to change lowercase to upper without toupper()

here is my function


Expand|Select|Wrap|Line Numbers
  1. char* upper( char* str){
  2.  
  3. int length = strlen(str);
  4.  
  5. char* string_new = ( char* )malloc(sizeof( int ) *( 256 ) );
  6.  
  7. int i;
  8.  
  9. printf( " This is the original sentence : %s \n" , str );
  10.  
  11. for( i = 0 ; i < length ; i++ ){
  12.  
  13. if( str[i] >= 97 && str[i] <= 122 ){
  14.  
  15. string_new[i] = str[i] - 32 ;
  16.  
  17. }
  18. else if( str[i] == 0 ){
  19.  
  20. break;
  21.  
  22.  
  23.  
  24.  
  25.  
  26. }
  27. printf( " %s \n " , string_new );
  28. return string_new;
May 3 '10 #1
2 2049
donbock
2,426 Expert 2GB
Use CODE tags, they make your code easier to read.

Presumably you are not happy with the result of this function. You will get better help if you tell us (a) what you expected to get; and (b) how your actual result differs from your expectations.

How did you decide that the size of string_new should be sizeof(int)*256?

I see three magic numbers in your program: 97, 122, and 32. Where did these numbers come from? What do they mean?
(Hint: I'm asking because there is a better way to express them.)

What should your loop do for characters that are not 0 or between 97 and 122?
May 3 '10 #2
whodgson
542 512MB
I don`t think the if and else if braces are needed also :
Expand|Select|Wrap|Line Numbers
  1. if(c>='a' && c<='z')c+='A'-'a';
will change a lower case character to upper case
May 3 '10 #3

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

Similar topics

9
by: Brett | last post by:
I'm developing with CF 5 and SQL Server 2000. I think they are both great products. The major draw is their cost. I don't develop stand alone products because anyone that wants to purchase them...
1
by: JimA | last post by:
I have an application that needs to execute dtsrun from a remote machine. Basically I have a batch file on the remote box, which handles the execute. This works fine on a machine with client tools...
0
by: Shane Story | last post by:
My other thread on serialization seemed to be stagnant and I still have questions, so I decided to post this example of what I need to know. I am trying to use binaryformatter. I have no trouble...
48
by: Frederick Gotham | last post by:
The "toupper" function takes an int as an argument. That's not too irrational given that a character literal is of type "int" in C. (Although why it isn't of type "char" escapes me... ) The...
3
by: dotnetnoob | last post by:
this is my code Do Dim nn As String Dim strNetControl As String = CStr(arlsNetControl.Item(y)) rootDoc.Load(strNetControl) lsSubNetInst =...
2
by: engwar1 | last post by:
I'm a .Net newbie and have started writing a Windows Forms application to assist me in choosing files/directories to move from one drive to another. Basically what I want is something like the...
0
by: venkat245 | last post by:
Hi, i want code for change the password without asp membership now i am doing asp.net with c# plz help me
5
by: Kaosman | last post by:
I have been trying to figure out this problem for a while. All I want to do is have a combo box populate a list box and the list box change to the record based on the users choice. The combo...
3
by: muddasirmunir | last post by:
I am trying to give the following Icon in my form in vb6. http://www.mediafire.com/?ymzgkgyi50j But , when I put this in my form I got error "Invalid Picutre" What wrong in it? How to add...
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: 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:
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...
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
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.