|
//this program is to change the Upper case to lower and vice-versa
#include<stdio.h>
void main()
{char name[50];
int i;
gets(name);
for(i=0;name[i];i++)
{
if(65<=name[i]<=90)
name[i]=name[i]+32;
else if(97<=name[i]<122)
name[i]=name[i]-32;
}
puts(name);
}
|
|
|
|
|
Don't use decimal numbers to represent characters, it makes it more difficult to understand. Use hex numbers or, better still, proper character constants. Also you cannot use expressions like if(65<=name[i]<=90) ; that is not valid C.
if(name[i] >= 'A' && name[i] <= 'Z')
name[i] = name[i] + 0x20;
else if(name[i] >= 'a' && name[i] <= 'z')
name[i] = name[i] - 0x20;
}
And finally, this is the Managed C++/CLI forum, the C/C++/MFC forum is at C / C++ / MFC Discussion Boards[^].
|
|
|
|
|
Richard MacCutchan wrote: ... expressions like if(65<=name[i]<=90) ; that is not valid C
Strictly speaking, that is valid C, though it does not do what you might expect. In fact it will always return 1 (true), since it is equivalent to if ( (65 <= name[i]) <= 90) . The expression (65 <= name[i]) evaluates to either true (1) or false (0), both of which are <= 90, so the expression will always be true.
Better than using "magic numbers", or even char constants, why not useisupper(), islower(), toupper() and tolower()) ?
#include <ctype.h>
if( islower(name[i] )
name[i] = toupper(name[i]);
else if ( isupper(name[i]) )
name[i] = tolower(name[i]);
That's clear and concise, I think, and has the advantage that if you need to migrate to an non ASCII environment [e.g. EBCDIC, but not UTF-X (and really, who does, these days?)], it will still work without any code changes. It will also work for locales other that C/POSIX
For the advanced reader I offer, also
name[i] = isupper(name[i]) ? tolower(name[i]) : toupper(name[i])
toupper() and tolower() only transform characters that evaluate true for isupper() and islower() , respectively, so non alphabetic chars are not changed by passing through them. The ternary ?: operator should be approached with caution though, as it often makes code harder to understand, particularly for users new to C
Keep Calm and Carry On
|
|
|
|
|
Yes that is all very well. But my reply was for someone who obviously only knows the very basics of C, and even that not very well. Trying to explain ternary operators to someone who does not really understand binary ones is not the best way forward.
|
|
|
|
|
Also, 7 bit ASCII is historical.
The very minimum requirement today is to handle ISO 8859-1 in the Western world (8859-x in other parts). But for software developed this millennium, the real minimum requirement is the Unicode Basic Multilingual Plane. (In fact, I do not know if there concept of upper/lower cases is relevant for any characters outside the BMP.)
Handling a-z only belongs back in the age of 80-column punched cards.
|
|
|
|
|
Look at the question. This is a basic classroom assignment for people with no programming background.
|
|
|
|
|
How can I run this command:
pdfcompress.exe "c:\currentfile.pdf" "c:\newfile.pdf"
I dont see how I can use ShellExecute to send these 2 arguments.
Is there some other command I can use along with these arguments
to execute this file? Please let me know.
|
|
|
|
|
|
|
Hello
I Am building a windows form application that accept an expression involving two variables and two numerical values for the variables through a text box.
the App is then suppose to display a functional value for the user.
I tried everything possible but keep getting error "input string was not in correct format"
Thanks in advance for your help (anyone).
|
|
|
|
|
F_Square wrote: error "input string was not in correct format" Most likely you are trying to convert some characters into a numeric, but it contains letters or special characters. However, since you have not shown us your code, or the data that it is trying to access, that is just a guess.
|
|
|
|
|
you're right
what I want the program to do is accept an expression involving two variables from the user together with values.
the program is then suppose to return a functional value as double
|
|
|
|
|
That sounds simple enough.
|
|
|
|
|
Hi,
Need technical help . I am debugging the code and getting this
"Source information is missing from the debug information for this module" . while debuggin.
I am referring .dll in the code, that .dll is also build debug. and while debugging the code i have added (dll refered) project
in my project. still it not loading to breakpoint.
Could you please guide me on this?
|
|
|
|
|
Check your project settings for the dll file to ensure that all the debugging information is being created when the file is built.
|
|
|
|
|
Whether that dll is built in debug mode doesn't matter for debugging, in spite of the name! What you need is the .pdb file for that DLL. The .pdb file contains all the references that link the compiled code segments to the original code statements. If you have the .pdb, make sure it's accessible, e. g. in the same directory as the .dll file, or in the directory of your application.
If you have that DLL in your solution, includ9ing the source code, you should check your build options and make sure a .pdb is actually built.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
Hi there, I am having the big problem with getting the area of hwind with
routine GetWindowRect. Even Spy++ or his implementation returns rectangle, that is smaller than real
area. Its a some special kind of application, I am looking for some alternative to GetWindowRect,
or how can I get all the window area programmatically correct.
|
|
|
|
|
The GetWindowRect function returns the correct size of any window. If your code is not working then you need to provide more details.
|
|
|
|
|
Its casino application, I am using GetWindowRect standard way.
|
|
|
|
|
Sorry, but that tells us nothing.
|
|
|
|
|
Could you show your code?
|
|
|
|
|
HWND hwnd = FindWindow("HwndWrapper[PokerClient.exe;;518cf654-e6cb-47c5-9916-be16cbf1e961]", NULL);
GetWindowRect(hwnd, &wr);
AdjustWindowRect(&wr, WS_BORDER, true);
As I said its weird behaviour of GetWindowRect
Edited code, it was from the last operation when I was trying
get also parent window.
modified 30-Mar-20 7:59am.
|
|
|
|
|
lacir wrote:
HWND hwnd = FindWindow("HwndWrapper[PokerClient.exe;;518cf654-e6cb-47c5-9916-be16cbf1e961]", NULL);
GetWindowRect(parrent, &wr);
AdjustWindowRect(&wr, WS_BORDER, true);
You call FindWindow but then ignore the value it returns.
Then you are using some other value parrent as a windows handle to obtain the window rectangle for.
Is it what you want?
|
|
|
|
|
This line:
GetWindowRect(parrent, &wr);
Should (probably!) either be:
GetWindowRect(hwnd, &wr);
Or:
GetWindowRect(GetParent(hwnd), &wr);
|
|
|
|
|
I don't know...
The OP seems to disappear...
|
|
|
|