By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,898 Members | 2,012 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,898 IT Pros & Developers. It's quick & easy.

a big problem

P: n/a
ash
there is a question:

write a program which when executed would keep coverting every capital
letter on the screen to small case letter and every small case letter
to capital letter.The procedure should stop the movement the user hits
a key from keyboard.

I had "Let us C" book and this question on page 278, I m trying my best
but unable to do till now, any one knows what to do.
thankx and genious i will say who will do it

Dec 25 '05 #1
Share this Question
Share on Google+
32 Replies


P: n/a
ash wrote:
there is a question:

write a program which when executed would keep coverting every capital
letter on the screen to small case letter and every small case letter
to capital letter.The procedure should stop the movement the user hits
a key from keyboard.
It is not a question, it is a homework...
I had "Let us C" book and this question on page 278, I m trying my best
but unable to do till now, any one knows what to do.
thankx and genious i will say who will do it


Show us the best you did and someone will guide you...

Dec 25 '05 #2

P: n/a
ash
ok
there is some code

#include<stdio.h>
#include<dos.h>

main()
{
char far *scr=0xB8000000;
int i
while(!kbhit())
{
for(i=0;i<=3999;i+=2)
if(scr[i]>='A' &7 scr[i]<='Z')
{
scr[i]+=32;
}
else
{
if(scr[i]>='a'&&scr[i]<='z')
{
scr[i]-=32;
}}
}}

this is its answer but when i run this program nothing happened i have
turbo C++ 3.1
i was not trying to convience for doing my homework my friends

Dec 25 '05 #3

P: n/a
Turbo C++ 3.1, Oh, an IDE which has been out of the day yet.
Hmm, you've made some literal mistakes, I marked them after "//"

#include<stdio.h>
#include<dos.h>
main()
{
char far *scr=0xB8000000; //the compile message show "warning"
int i // semicolon missed
while(!kbhit()) // it can make the exe file trap in dead recycling
{
for(i=0;i<=3999;i+=2)
if(scr[i]>='A' &7 scr[i]<='Z') // the digit 7 should be delete
{
scr[i]+=32;
}
else
{
if(scr[i]>='a'&&scr[i]<='z')
{
scr[i]-=32;
}}
}}

Although I compiled it succeefully, it's not a normal program. And I
will examine it later.

Dec 25 '05 #4

P: n/a

"ash" <as************@rediffmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
ok
there is some code

#include<stdio.h>
#include<dos.h>

main()
{
char far *scr=0xB8000000;
int i
while(!kbhit())
{
for(i=0;i<=3999;i+=2)
if(scr[i]>='A' &7 scr[i]<='Z')
{
scr[i]+=32;
}
else
{
if(scr[i]>='a'&&scr[i]<='z')
{
scr[i]-=32;
}}
}}

this is its answer but when i run this program nothing happened i have
turbo C++ 3.1
i was not trying to convience for doing my homework my friends


You're trying to access VGA [colour] memory in 'text mode' as far as I can
tell (plus there's no ';' after int i and &7 should be &&, 'far' is
obselete).

Is this an old book?
Dec 25 '05 #5

P: n/a
ash
yes plz suggest me
i wanna master in c
what compiler should i use
help me

Dec 25 '05 #6

P: n/a
ash
sorry it was my typing mistake but the main problem remains there.Plz
read the question carefully then give me a right answer

Dec 25 '05 #7

P: n/a
ash
sorry it was my typing mistake but the main problem remains there.Plz
read the question carefully then give me a right answer

Dec 25 '05 #8

P: n/a
How about this?

#include<stdio.h>

int main()
{
char scr;

printf("input the character: ");
scanf("%s", &scr);

if (scr >= 'A' && scr <= 'Z')
{
scr += 32;
}
if (scr >= 'a'&& scr <= 'z')
{
scr -= 32;
}

printf("the result is: %s", &scr);

return 0;
}

Simple code is ok, i think.
The IDE I used is Dev-C++ 4.9.9.0.

Dec 25 '05 #9

P: n/a
ash
write a program which when executed would keep coverting every capital
letter on the screen to small case letter and every small case letter
to capital letter.The procedure should stop the movement the user hits
a key from keyboard.

this is my problem.
your solution will won`t work my friend but nice try

Dec 25 '05 #10

P: n/a
ash
write a program which when executed would keep coverting every capital
letter on the screen to small case letter and every small case letter
to capital letter.The procedure should stop the movement the user hits
a key from keyboard.

this is my problem.
your solution will won`t work my friend but nice try

Dec 25 '05 #11

P: n/a
On Sun, 25 Dec 2005, ash <as************@rediffmail.com> wrote:-
sorry it was my typing mistake but the main problem remains there.Plz
read the question carefully then give me a right answer


This is pseudo-code but it might do:

/*
you might need to adjust these
*/
#include <stdio.h>
#include <dos.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>

main()
{
char far *scr=0xb8000000;
int offset=0;

while(!kbhit())
{
for(offset=0;offset<4000;offset+=2)
{
if(isalpha(scr[offset])) /* check the character is a letter */
{
if(isupper(scr[offset])) /* is it upper case? */
{
scr[offset]=tolower(scr[offset]); /* yes. Convert to lower case */
}
else
{
scr[offset]=toupper(scr[offset]); /* no. convert to upper case */
}
}
}
}
exit 0;
}

You could also replace:

if(isalpha(scr[offset])) /* check the character is a letter */
{
if(isupper(scr[offset])) /* is it upper case? */
{
scr[offset]=tolower(scr[offset]); /* yes. Convert to lower case */
}
else
{
scr[offset]=toupper(scr[offset]); /* no. convert to upper case */
}
}

with:

if(isalpha(scr[offset])) /* check the character is a letter */
{
scr[offset]^=32;
}

Unfortunately, I don't have access to an old DOS compiler to test the
above but it should work, possibly after a little tweaking.
Regards,
David Bolt

--
Member of Team Acorn checking nodes at 50 Mnodes/s: http://www.distributed.net/
AMD1800 1Gb WinXP/SUSE 9.3 | AMD2400 256Mb SuSE 9.0 | A3010 4Mb RISCOS 3.11
AMD2400(32) 768Mb SUSE 10.0 | RPC600 129Mb RISCOS 3.6 | Falcon 14Mb TOS 4.02
AMD2600(64) 512Mb SUSE 10.0 | A4000 4Mb RISCOS 3.11 | STE 4Mb TOS 1.62
Dec 25 '05 #12

P: n/a
ash a crit :
ok
there is some code

#include<stdio.h>
#include<dos.h>
starts badly...
main()
{
char far *scr=0xB8000000;


WTF! How is this old PC/MS-DOS hack ralated with you question ?

If you are learning C, please stick to the standard and portable code.
BTW, don't waiste your time with obsolet hacks suposed to work on
machines with a lousy OS...

Modern OS'es don't support this kind of abobination and will kill such a
devilish process..

Try this :

http://publications.gbdirect.co.uk/c_book/

--
A+

Emmanuel Delahaye
Dec 25 '05 #13

P: n/a
ir********@gmail.com a crit :
if (scr >= 'A' && scr <= 'Z')


Not portable hack. Works fine with ASCII but neither with extended ISO
characters (iso-8859-1), nor with EBCDIC for example.

--
A+

Emmanuel Delahaye
Dec 25 '05 #14

P: n/a
"ash" <as************@rediffmail.com> writes:
there is a question:

write a program which when executed would keep coverting every capital
letter on the screen to small case letter and every small case letter
to capital letter.The procedure should stop the movement the user hits
a key from keyboard.

I had "Let us C" book and this question on page 278, I m trying my best
but unable to do till now, any one knows what to do.
thankx and genious i will say who will do it


Standard C provides no way to retrieve characters on the screen. On
many systems, there's no portable way to do this unless you've kept
track of what you've written to the screen yourself.

Standard C provides no way to interrupt a program when a key is
pressed. If you try to read a character from stdin, the program will
block until the user enters a newline.

Try a newsgroup that deals with whatever system you're using.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Dec 25 '05 #15

P: n/a
ash a crit :
yes plz suggest me
i wanna master in c
what compiler should i use


Please check your spelling. English is not my native language, and I
have hard time trying to decode your langage...

I guess that your platform is a PC with a 32-bit Windows. You can try
Code::Blocks.

http://www.codeblocks.org/

--
A+

Emmanuel Delahaye
Dec 25 '05 #16

P: n/a

"ash" <as************@rediffmail.com> wrote
write a program which when executed would keep coverting every capital
letter on the screen to small case letter and every small case letter
to capital letter.The procedure should stop the movement the user hits
a key from keyboard.

I had "Let us C" book and this question on page 278, I m trying my best
but unable to do till now, any one knows what to do.
thankx and genious i will say who will do it

The logic is trivial - just call toupper() and tolower() to convert the
characters.

The hard part is addressing the screen. Virtually all C compilers come with
some sort of non-standard library for accessing character-mapped screens.
Under Unix it will usually be called "curses" whilst under DOS you include a
(non-standard) header called "conio.h".
Look up the function in these and try to use them. Unfortunately the details
are not on topic here.
Dec 25 '05 #17

P: n/a
Emmanuel Delahaye wrote:
ir********@gmail.com a crit :
if (scr >= 'A' && scr <= 'Z')


Not portable hack. Works fine with ASCII but neither with extended ISO
characters (iso-8859-1), nor with EBCDIC for example.


This will work with EBCDIC. It will even work, amazingly, with Baudot.
In fact, it will even work with Morse code. When designing character
sets, humans have a tendency to make A-Z contiguous. (Of course, for
Baudot and Morse A-Z exists but there are no a-z).

Dec 25 '05 #18

P: n/a
ash wrote:
ok
there is some code

#include<stdio.h>
#include<dos.h>

main()
{
char far *scr=0xB8000000;
int i
while(!kbhit())
{
for(i=0;i<=3999;i+=2)
if(scr[i]>='A' &7 scr[i]<='Z')
{
scr[i]+=32;
}
else
{
if(scr[i]>='a'&&scr[i]<='z')
{
scr[i]-=32;
}}
}}

this is its answer but when i run this program nothing happened i have
turbo C++ 3.1
i was not trying to convience for doing my homework my friends


This is not C programming, it's DOS programming. The language used may
be C but the question posed have little to do with C (in fact,
impossible to do with C without additional help, form your OS or the
BIOS or your graphic card) but more to do with DOS and the Intel x86
platform.

This does illustrate the power of C - that you can do very low level
assembly-like programs and directly access hardware without any API or
device drivers (depends on your OS, try this on UNIX and you'll fail).
But again, it is more to do with how to write assembly-like programs in
C rather than how to write a C program.

Dec 25 '05 #19

P: n/a
sl*******@yahoo.com wrote:
Emmanuel Delahaye wrote:
ir********@gmail.com a crit :

if (scr >= 'A' && scr <= 'Z')


Not portable hack. Works fine with ASCII but neither with extended ISO
characters (iso-8859-1), nor with EBCDIC for example.

This will work with EBCDIC. It will even work, amazingly, with Baudot.
In fact, it will even work with Morse code. When designing character
sets, humans have a tendency to make A-Z contiguous. (Of course, for
Baudot and Morse A-Z exists but there are no a-z).

No. A-Z are not contiguous in EBCDIC. Baudot? Morse code doesn't have a
binary representation that I know of. What are you talking about?

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Dec 26 '05 #20

P: n/a
On 2005-12-25, sl*******@yahoo.com <sl*******@gmail.com> wrote:
Emmanuel Delahaye wrote:
ir********@gmail.com a crit :
> if (scr >= 'A' && scr <= 'Z')


Not portable hack. Works fine with ASCII but neither with extended ISO
characters (iso-8859-1), nor with EBCDIC for example.


This will work with EBCDIC.


A-Z are in order in EBCDIC but are not contiguous.
Dec 26 '05 #21

P: n/a
In article <11*********************@o13g2000cwo.googlegroups. com> "sl*******@yahoo.com" <sl*******@gmail.com> writes:
Emmanuel Delahaye wrote:
ir********@gmail.com a =E9crit :
if (scr >=3D 'A' && scr <=3D 'Z')


Not portable hack. Works fine with ASCII but neither with extended ISO
characters (iso-8859-1), nor with EBCDIC for example.


This will work with EBCDIC. It will even work, amazingly, with Baudot.
In fact, it will even work with Morse code. When designing character
sets, humans have a tendency to make A-Z contiguous. (Of course, for
Baudot and Morse A-Z exists but there are no a-z).


Eh? In Baudot the coding of '-' is between 'W' and 'T'. In what you
call Baudot (but actually is Murray), ' ' is between 'O' and 'H'. It
also does not work with EBCDIC because the backslash, the closing brace,
the hook and the fork are also in that range.

So what do you mean when you say that it works?
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Dec 26 '05 #22

P: n/a
ir********@gmail.com wrote:
How about this?

#include<stdio.h>

int main()
{
char scr;

printf("input the character: ");
scanf("%s", &scr);
Exactly how many characters do you think fit in to a single character?
Add to that C strings are terminated with a nul character and how long a
C string do you think fits in to a single character? In addition, the
"%s" format specifier for scanf (without limiting the length) is just as
bad as gets because it allows the user to enter a longer string than
fits in to the destination thus overwriting memory, so don't do that.
if (scr >= 'A' && scr <= 'Z')
A-Z are not guaranteed contiguous or to be in sequence. Loot up the is*
functions which are provided for a reason.
{
scr += 32;
Upper and lower case letters are not guaranteed to be separated by 32.
Look up the to* functions.
}
if (scr >= 'a'&& scr <= 'z')
{
scr -= 32;
}

printf("the result is: %s", &scr);

return 0;
}

Simple code is ok, i think.
It is simply atrocious code. You still have a *lot* to learn.
The IDE I used is Dev-C++ 4.9.9.0.


Irrelevant.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Dec 26 '05 #23

P: n/a
On 25 Dec 2005 15:22:03 -0800, in comp.lang.c , "sl*******@yahoo.com"
<sl*******@gmail.com> wrote:
When designing character
sets, humans have a tendency to make A-Z contiguous.


Er... What, you mean like abgdezeth ?

Thats a contiguous alphabetic sequence in the order which would make
perfect sense to millions of people.

(and lets not forget azerty....)

Mark McIntyre
--

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Dec 26 '05 #24

P: n/a
Mark McIntyre wrote:
On 25 Dec 2005 15:22:03 -0800, in comp.lang.c , "sl*******@yahoo.com"
<sl*******@gmail.com> wrote:
When designing character
sets, humans have a tendency to make A-Z contiguous.


Er... What, you mean like abgdezeth ?

Thats a contiguous alphabetic sequence in the order which would make
perfect sense to millions of people.

(and lets not forget azerty....)

Mark McIntyre


OK, OK. Sorry I was wrong. I knew I should have checked before posting..

Dec 27 '05 #25

P: n/a
Thank you very much! These faults knocked me back.
非常谢谢*,我对这些错误感动很震 。
Dec 28 '05 #26

P: n/a
Thank you very much! These faults knocked me back.
非常谢谢*!我对这些错误感到很震 。
Dec 28 '05 #27

P: n/a
hehe, thanks^_^

Dec 28 '05 #28

P: n/a
thanks.

Dec 28 '05 #29

P: n/a
"Malcolm" <re*******@btinternet.com> writes:
The hard part is addressing the screen. Virtually all C compilers
come with some sort of non-standard library for accessing character-
mapped screens.


What is this "screen" you speak of? I've searched through my copy of
the standard but found no mention of it.

DES
--
Dag-Erling Smrgrav - de*@des.no
Dec 30 '05 #30

P: n/a
""Dag-Erling Smrgrav"" <de*@des.no> wrote
"Malcolm" <re*******@btinternet.com> writes:
The hard part is addressing the screen. Virtually all C compilers
come with some sort of non-standard library for accessing character-
mapped screens.


What is this "screen" you speak of? I've searched through my copy of
the standard but found no mention of it.

Raster (addressable, modifiable pixels) devices attached to computers as
output devices.

The libraries to access them are non-standard, so the standard has no need
to mention such a thing.
Dec 30 '05 #31

P: n/a
On Fri, 30 Dec 2005 23:30:09 +0000 (UTC), in comp.lang.c , "Malcolm"
<re*******@btinternet.com> wrote:
""Dag-Erling Smrgrav"" <de*@des.no> wrote
"Malcolm" <re*******@btinternet.com> writes:
The hard part is addressing the screen. Virtually all C compilers
come with some sort of non-standard library for accessing character-
mapped screens.


What is this "screen" you speak of? I've searched through my copy of
the standard but found no mention of it.

Raster (addressable, modifiable pixels) devices attached to computers as
output devices.


Your sarcasm detector is broken. It seems exceptionally likely that
Dag-Erling knew this.
Mark McIntyre
--

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Dec 31 '05 #32

P: n/a
Dag-Erling Smrgrav said:
"Malcolm" <re*******@btinternet.com> writes:
The hard part is addressing the screen. Virtually all C compilers
come with some sort of non-standard library for accessing character-
mapped screens.


What is this "screen" you speak of?


Screen is a full-screen window manager that multiplexes a
physical terminal between several processes (typically
interactive shells). Each virtual terminal provides the
functions of a DEC VT100 terminal and, in addition, sev-
eral control functions from the ISO 6429 (ECMA 48, ANSI
X3.64) and ISO 2022 standards (e.g. insert/delete line and
support for multiple character sets). There is a scroll*-
back history buffer for each virtual terminal and a copy-
and-paste mechanism that allows moving text regions
between windows.

(From the man page.)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Dec 31 '05 #33

This discussion thread is closed

Replies have been disabled for this discussion.