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

convert problem

P: 3
Hello, sorry but my English is not so very wel.

i am trying to right a code to convert a letter but i can do it works en y dont found the problem.
i hope you can help me en give explanation please. Tks

here my code:

Expand|Select|Wrap|Line Numbers
  1. /* leeskl.c */
  2. /* stuurt als resultaat een teken terug */
  3. /* en zet hoodletters om in kleine letters */
  4.  
  5. #include<stdio.h> 
  6. #include<conio.h>
  7.  
  8. char leeskl(void);
  9. main() 
  10. {     
  11.     char ch;
  12.     ch = getche();                                      /* lees teken */
  13.     if ( ch>64 && ch<91 )                               /* als het teken een hoofdletter is */
  14.        return (ch +32);                                 /* stuur geconverteerd teken terug */
  15.       else                                              /* en zo niet */
  16.        return (ch);                                     /* stuur oorspronkelijk teken terug */                                                                                
  17.  
  18. }
2 Weeks Ago #1
Share this Question
Share on Google+
5 Replies


dev7060
P: 77
Several things:

- You need to write the desired code in the function's body.
Expand|Select|Wrap|Line Numbers
  1. //functions' declarations
  2. main(){
  3. ...
  4. }
  5. //functions' definitions
  6. fun1(){
  7. ...
  8. }
  9. fun2(){
  10. ...
  11. }
  12.  
- Function has to be called from main.
- Since the function is returning char data type, it can either be stored in a variable or can be shown directly to the console.
Expand|Select|Wrap|Line Numbers
  1. char newCh=leeskl();
  2.  
or
Expand|Select|Wrap|Line Numbers
  1. printf("%c", leeskl());
  2.  
- Other than that, the logic for uppercase to lowercase looks fine.
2 Weeks Ago #2

P: 3
Hello dev 7060,

Many thanks for your answer,
I try hit out but it is not so easy for my dear first i am invalid and 70 years old and reseive from my sun a book for learn c and so have a occupation. But my English is very bad but i do my best.

I try i out and let you now.
Greathings, CP70
2 Weeks Ago #3

P: 3
Dear dev7060,
here my solution:
Code:
Expand|Select|Wrap|Line Numbers
  1. /* leeskln2.c */
  2. /* test de functie leeskln */
  3.  
  4. #include<stdio.h> 
  5. #include<conio.h>
  6. char leeskl(void);                          /* functieprototype voor lijn let op de ; */
  7. main()
  8.  
  9. {
  10.     char chkl;                              /*het teken dat wordt teruggestuurd */
  11.  
  12.     printf("Typ 'a'voor de eerste optie, 'b'voor de tweede: ");
  13.     chkl = leeskl();                        /* lees geconverteerd teken */
  14.     switch (chkl)                           /* druk afhankelijk van teken, meded. af */
  15.          {
  16.          case 'a':
  17.              printf("\nU typte een 'a'.");
  18.              break;
  19.          case 'b':
  20.              printf("\nU typte een 'b'.");
  21.              break;
  22.          default:
  23.              printf("\nU koos een niet bestaande optie.");                   
  24.           } 
  25. }
  26.  
  27. /* leeskl */
  28. /* stuur als resultaatwaarde een teken terug */
  29. /* zet hoofdletters om in kleine letters */
  30.  
  31.  
  32.  
  33.  
  34. char leeskl(void) 
  35. {     
  36.  
  37.     char ch;
  38.     ch = getche();                /* lees teken */
  39.     if ( ch>64 && ch<91 )         /* als het teken een hoofdletter is */
  40.        return (ch + 32);          /* stuur geconverteerd teken terug */
  41.      else                         /* en zo niet */
  42.        return (ch);               /* stuur oorspronkelijk teken terug */                                                                                
  43. }
Now its working perfectly!
dev7060 many Thanks to you for spend your time to help me!
and also to the Bytes.com friends.
2 Weeks Ago #4

P: 8
I also hava a suggestion to your code - i would like to add a void or int before the main():
Expand|Select|Wrap|Line Numbers
  1. void main() {
  2.     //some code
  3.     return;//not essential
  4. }
  5.  
or:
Expand|Select|Wrap|Line Numbers
  1. int main() {
  2.     //some code
  3.     return 0;
  4.     // ESSENTIAL if using "int" 
  5. }
  6.  
Because i'm a c++ coder, so maybe c can't use int.
1 Week Ago #5

P: 8
BTW thanks should be thx not tks
1 Week Ago #6

Post your reply

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