a big problem

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
 
G

Giannis Papadopoulos

ash said:
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...
 
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>='A' &7 scr<='Z')
{
scr+=32;
}
else
{
if(scr>='a'&&scr<='z')
{
scr-=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
 
I

iridiumcao

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>='A' &7 scr<='Z') // the digit 7 should be delete
{
scr+=32;
}
else
{
if(scr>='a'&&scr<='z')
{
scr-=32;
}}
}}

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

pemo

ash said:
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>='A' &7 scr<='Z')
{
scr+=32;
}
else
{
if(scr>='a'&&scr<='z')
{
scr-=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?
 
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
 
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
 
I

iridiumcao

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

David Bolt

On Sun said:
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
 
E

Emmanuel Delahaye

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/
 
E

Emmanuel Delahaye

(e-mail address removed) 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.
 
K

Keith Thompson

ash said:
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.
 
E

Emmanuel Delahaye

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/
 
M

Malcolm

ash said:
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.
 
S

slebetman

Emmanuel said:
(e-mail address removed) a écrit :


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

slebetman

ash said:
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>='A' &7 scr<='Z')
{
scr+=32;
}
else
{
if(scr>='a'&&scr<='z')
{
scr-=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.
 
J

Joe Wright

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top