convert problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CP70
    New Member
    • Jul 2019
    • 3

    convert problem

    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:

    Code:
    /* leeskl.c */
    /* stuurt als resultaat een teken terug */
    /* en zet hoodletters om in kleine letters */
    
    #include<stdio.h> 
    #include<conio.h>
    
    char leeskl(void);
    main() 
    {	 
    	char ch;
    	ch = getche();                                      /* lees teken */
    	if ( ch>64 && ch<91 )                               /* als het teken een hoofdletter is */
    	   return (ch +32);                                 /* stuur geconverteerd teken terug */
    	  else                                              /* en zo niet */
    	   return (ch);                                     /* stuur oorspronkelijk teken terug */                                                                                
        
    }
    Last edited by gits; Jul 8 '19, 06:50 AM. Reason: added code tags
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 656

    #2
    Several things:

    - You need to write the desired code in the function's body.
    Code:
    //functions' declarations
    main(){
    ...
    }
    //functions' definitions
    fun1(){
    ...
    }
    fun2(){
    ...
    }
    - 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.
    Code:
    char newCh=leeskl();
    or
    Code:
    printf("%c", leeskl());
    - Other than that, the logic for uppercase to lowercase looks fine.

    Comment

    • CP70
      New Member
      • Jul 2019
      • 3

      #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

      Comment

      • CP70
        New Member
        • Jul 2019
        • 3

        #4
        Dear dev7060,
        here my solution:
        Code:
        Code:
        /* leeskln2.c */
        /* test de functie leeskln */
        
        #include<stdio.h> 
        #include<conio.h>
        char leeskl(void);                          /* functieprototype voor lijn let op de ; */
        main()
        
        {
        	char chkl;                              /*het teken dat wordt teruggestuurd */
        	
        	printf("Typ 'a'voor de eerste optie, 'b'voor de tweede: ");
        	chkl = leeskl();                        /* lees geconverteerd teken */
        	switch (chkl)                           /* druk afhankelijk van teken, meded. af */
        	     {
        	     case 'a':
        		     printf("\nU typte een 'a'.");
        		     break;
        		 case 'b':
        		     printf("\nU typte een 'b'.");
        			 break;
        		 default:
        		     printf("\nU koos een niet bestaande optie.");	 	 	 	
        		  } 
        }
        
        /* leeskl */
        /* stuur als resultaatwaarde een teken terug */
        /* zet hoofdletters om in kleine letters */
        
        
        
        
        char leeskl(void) 
        {	 
        	
        	char ch;
        	ch = getche();                /* lees teken */
        	if ( ch>64 && ch<91 )         /* als het teken een hoofdletter is */
        	   return (ch + 32);          /* stuur geconverteerd teken terug */
        	 else                         /* en zo niet */
        	   return (ch);               /* stuur oorspronkelijk teken terug */                                                                                
        }
        Now its working perfectly!
        dev7060 many Thanks to you for spend your time to help me!
        and also to the Bytes.com friends.
        Last edited by gits; Jul 8 '19, 06:53 AM. Reason: added code tags

        Comment

        • chrimpylimes
          New Member
          • Jul 2019
          • 10

          #5
          I also hava a suggestion to your code - i would like to add a void or int before the main():
          Code:
          void main() {
              //some code
              return;//not essential
          }
          or:
          Code:
          int main() {
              //some code
              return 0;
              // ESSENTIAL if using "int" 
          }
          Because i'm a c++ coder, so maybe c can't use int.
          Last edited by chrimpylimes; Jul 9 '19, 09:22 AM. Reason: Didn't add "}" after int main.

          Comment

          • chrimpylimes
            New Member
            • Jul 2019
            • 10

            #6
            BTW thanks should be thx not tks

            Comment

            Working...