Connecting Tech Pros Worldwide Forums | Help | Site Map

a big problem

ash
Guest
 
Posts: n/a
#1: Dec 25 '05
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

Giannis Papadopoulos
Guest
 
Posts: n/a
#2: Dec 25 '05

re: a big problem


ash wrote:[color=blue]
> 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.[/color]

It is not a question, it is a homework...
[color=blue]
> 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[/color]

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

ash
Guest
 
Posts: n/a
#3: Dec 25 '05

re: a big problem


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

iridiumcao@gmail.com
Guest
 
Posts: n/a
#4: Dec 25 '05

re: a big problem


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.

pemo
Guest
 
Posts: n/a
#5: Dec 25 '05

re: a big problem



"ash" <ashishmourya21@rediffmail.com> wrote in message
news:1135523687.844365.296090@o13g2000cwo.googlegr oups.com...[color=blue]
> 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[/color]

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?


ash
Guest
 
Posts: n/a
#6: Dec 25 '05

re: a big problem


yes plz suggest me
i wanna master in c
what compiler should i use
help me

ash
Guest
 
Posts: n/a
#7: Dec 25 '05

re: a big problem


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

ash
Guest
 
Posts: n/a
#8: Dec 25 '05

re: a big problem


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

iridiumcao@gmail.com
Guest
 
Posts: n/a
#9: Dec 25 '05

re: a big problem


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.

ash
Guest
 
Posts: n/a
#10: Dec 25 '05

re: a big problem


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

ash
Guest
 
Posts: n/a
#11: Dec 25 '05

re: a big problem


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

David Bolt
Guest
 
Posts: n/a
#12: Dec 25 '05

re: a big problem


On Sun, 25 Dec 2005, ash <ashishmourya21@rediffmail.com> wrote:-
[color=blue]
>sorry it was my typing mistake but the main problem remains there.Plz
>read the question carefully then give me a right answer[/color]

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
Emmanuel Delahaye
Guest
 
Posts: n/a
#13: Dec 25 '05

re: a big problem


ash a écrit :[color=blue]
> ok
> there is some code
>
> #include<stdio.h>
> #include<dos.h>[/color]

starts badly...
[color=blue]
> main()
> {
> char far *scr=0xB8000000;[/color]

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
Emmanuel Delahaye
Guest
 
Posts: n/a
#14: Dec 25 '05

re: a big problem


iridiumcao@gmail.com a écrit :
[color=blue]
> if (scr >= 'A' && scr <= 'Z')[/color]

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

--
A+

Emmanuel Delahaye
Keith Thompson
Guest
 
Posts: n/a
#15: Dec 25 '05

re: a big problem


"ash" <ashishmourya21@rediffmail.com> writes:[color=blue]
> 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[/color]

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) kst-u@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.
Emmanuel Delahaye
Guest
 
Posts: n/a
#16: Dec 25 '05

re: a big problem


ash a écrit :[color=blue]
> yes plz suggest me
> i wanna master in c
> what compiler should i use[/color]

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
Malcolm
Guest
 
Posts: n/a
#17: Dec 25 '05

re: a big problem



"ash" <ashishmourya21@rediffmail.com> wrote[color=blue]
> 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
>[/color]
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.


slebetman@yahoo.com
Guest
 
Posts: n/a
#18: Dec 25 '05

re: a big problem


Emmanuel Delahaye wrote:[color=blue]
> iridiumcao@gmail.com a écrit :
>[color=green]
> > if (scr >= 'A' && scr <= 'Z')[/color]
>
> Not portable hack. Works fine with ASCII but neither with extended ISO
> characters (iso-8859-1), nor with EBCDIC for example.
>[/color]

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).

slebetman@yahoo.com
Guest
 
Posts: n/a
#19: Dec 25 '05

re: a big problem


ash wrote:[color=blue]
> 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[/color]

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.

Joe Wright
Guest
 
Posts: n/a
#20: Dec 26 '05

re: a big problem


slebetman@yahoo.com wrote:[color=blue]
> Emmanuel Delahaye wrote:
>[color=green]
>>iridiumcao@gmail.com a écrit :
>>
>>[color=darkred]
>>>if (scr >= 'A' && scr <= 'Z')[/color]
>>
>>Not portable hack. Works fine with ASCII but neither with extended ISO
>>characters (iso-8859-1), nor with EBCDIC for example.
>>[/color]
>
>
> 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).
>[/color]
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 ---
Jordan Abel
Guest
 
Posts: n/a
#21: Dec 26 '05

re: a big problem


On 2005-12-25, slebetman@yahoo.com <slebetman@gmail.com> wrote:[color=blue]
> Emmanuel Delahaye wrote:[color=green]
>> iridiumcao@gmail.com a écrit :
>>[color=darkred]
>> > if (scr >= 'A' && scr <= 'Z')[/color]
>>
>> Not portable hack. Works fine with ASCII but neither with extended ISO
>> characters (iso-8859-1), nor with EBCDIC for example.
>>[/color]
>
> This will work with EBCDIC.[/color]

A-Z are in order in EBCDIC but are not contiguous.
Dik T. Winter
Guest
 
Posts: n/a
#22: Dec 26 '05

re: a big problem


In article <1135552923.468115.96380@o13g2000cwo.googlegroups. com> "slebetman@yahoo.com" <slebetman@gmail.com> writes:[color=blue]
> Emmanuel Delahaye wrote:[color=green]
> > iridiumcao@gmail.com a =E9crit :
> >[color=darkred]
> > > if (scr >=3D 'A' && scr <=3D 'Z')[/color]
> >
> > Not portable hack. Works fine with ASCII but neither with extended ISO
> > characters (iso-8859-1), nor with EBCDIC for example.[/color]
>
> 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).[/color]

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/
Flash Gordon
Guest
 
Posts: n/a
#23: Dec 26 '05

re: a big problem


iridiumcao@gmail.com wrote:[color=blue]
> How about this?
>
> #include<stdio.h>
>
> int main()
> {
> char scr;
>
> printf("input the character: ");
> scanf("%s", &scr);[/color]

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.
[color=blue]
> if (scr >= 'A' && scr <= 'Z')[/color]

A-Z are not guaranteed contiguous or to be in sequence. Loot up the is*
functions which are provided for a reason.
[color=blue]
> {
> scr += 32;[/color]

Upper and lower case letters are not guaranteed to be separated by 32.
Look up the to* functions.
[color=blue]
> }
> if (scr >= 'a'&& scr <= 'z')
> {
> scr -= 32;
> }
>
> printf("the result is: %s", &scr);
>
> return 0;
> }
>
> Simple code is ok, i think.[/color]

It is simply atrocious code. You still have a *lot* to learn.
[color=blue]
> The IDE I used is Dev-C++ 4.9.9.0.[/color]

Irrelevant.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Mark McIntyre
Guest
 
Posts: n/a
#24: Dec 26 '05

re: a big problem


On 25 Dec 2005 15:22:03 -0800, in comp.lang.c , "slebetman@yahoo.com"
<slebetman@gmail.com> wrote:
[color=blue]
>When designing character
>sets, humans have a tendency to make A-Z contiguous.[/color]

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 =----
slebetman@yahoo.com
Guest
 
Posts: n/a
#25: Dec 27 '05

re: a big problem


Mark McIntyre wrote:[color=blue]
> On 25 Dec 2005 15:22:03 -0800, in comp.lang.c , "slebetman@yahoo.com"
> <slebetman@gmail.com> wrote:
>[color=green]
> >When designing character
> >sets, humans have a tendency to make A-Z contiguous.[/color]
>
> 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
>[/color]

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

Xiaocao Feidao
Guest
 
Posts: n/a
#26: Dec 28 '05

re: a big problem


Thank you very much! These faults knocked me back.
éžå¸¸è°¢è°¢ä½*ï¼Œæˆ‘å¯¹è¿™äº›é”™è¯¯æ„ŸåŠ¨å¾ˆéœ‡æƒ Šã€‚
Xiaocao Feidao
Guest
 
Posts: n/a
#27: Dec 28 '05

re: a big problem


Thank you very much! These faults knocked me back.
éžå¸¸è°¢è°¢ä½*ï¼æˆ‘å¯¹è¿™äº›é”™è¯¯æ„Ÿåˆ°å¾ˆéœ‡æƒ Šã€‚
Xiaocao Feidao
Guest
 
Posts: n/a
#28: Dec 28 '05

re: a big problem


hehe, thanks^_^

Xiaocao Feidao
Guest
 
Posts: n/a
#29: Dec 28 '05

re: a big problem


thanks.

Dag-Erling Smørgrav
Guest
 
Posts: n/a
#30: Dec 30 '05

re: a big problem


"Malcolm" <regniztar@btinternet.com> writes:[color=blue]
> The hard part is addressing the screen. Virtually all C compilers
> come with some sort of non-standard library for accessing character-
> mapped screens.[/color]

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 Smørgrav - des@des.no
Malcolm
Guest
 
Posts: n/a
#31: Dec 30 '05

re: a big problem


""Dag-Erling Smørgrav"" <des@des.no> wrote[color=blue]
> "Malcolm" <regniztar@btinternet.com> writes:[color=green]
>> The hard part is addressing the screen. Virtually all C compilers
>> come with some sort of non-standard library for accessing character-
>> mapped screens.[/color]
>
> What is this "screen" you speak of? I've searched through my copy of
> the standard but found no mention of it.
>[/color]
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.


Mark McIntyre
Guest
 
Posts: n/a
#32: Dec 31 '05

re: a big problem


On Fri, 30 Dec 2005 23:30:09 +0000 (UTC), in comp.lang.c , "Malcolm"
<regniztar@btinternet.com> wrote:
[color=blue]
>""Dag-Erling Smørgrav"" <des@des.no> wrote[color=green]
>> "Malcolm" <regniztar@btinternet.com> writes:[color=darkred]
>>> The hard part is addressing the screen. Virtually all C compilers
>>> come with some sort of non-standard library for accessing character-
>>> mapped screens.[/color]
>>
>> What is this "screen" you speak of? I've searched through my copy of
>> the standard but found no mention of it.
>>[/color]
>Raster (addressable, modifiable pixels) devices attached to computers as
>output devices.[/color]

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 =----
Richard Heathfield
Guest
 
Posts: n/a
#33: Dec 31 '05

re: a big problem


Dag-Erling Smørgrav said:
[color=blue]
> "Malcolm" <regniztar@btinternet.com> writes:[color=green]
>> The hard part is addressing the screen. Virtually all C compilers
>> come with some sort of non-standard library for accessing character-
>> mapped screens.[/color]
>
> What is this "screen" you speak of?[/color]

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)
Closed Thread