How to convert lowercase letter to uppercase without library functions in C

3 Answers

0 votes
#include <stdio.h>
  
int main(void)
{
    char s[] = "The last line Of code";
    int i;
    
    // A - 65 .. Z - 90 (ASCII)
    // a - 97 .. Z - 122 (ASCII)
    // 97 - 65 = 32 

    while (s[i])
	{
        if (s[i] >= 97 && s[i] <= 122)
			s[i] = s[i] - 32;
		i++;
	}
	puts(s);
     
    return 0;
}
  
   
/*
     
run:
     
THE LAST LINE OF CODE

*/

 



answered Jan 29, 2016 by avibootz
edited Jan 29, 2016 by avibootz
0 votes
#include <stdio.h>
   
int main(void)
{
    char s[] = "The last line Of code";
    int i;
     
    // A - 65 .. Z - 90 (ASCII)
    // a - 97 .. Z - 122 (ASCII)
    // 97 - 65 = 32 
 
    while (s[i])
	{
        if (s[i] >= 'a' && s[i] <= 'z')
            s[i] = s[i] - 32;
		i++;
	}
     
    puts(s);
      
    return 0;
}
   
    
/*
      
run:
      
THE LAST LINE OF CODE
 
*/

 



answered Jan 29, 2016 by avibootz
0 votes
#include <stdio.h>
    
int main(void)
{
    char s[] = "The last line Of code";
    int i;
      
    // A - 65 .. Z - 90 (ASCII)
    // a - 97 .. Z - 122 (ASCII)
    // 97 - 65 = 32 
  
    while (s[i])
    {
        if (s[i] >= 'a' && s[i] <= 'z')
            s[i] = 'A' + s[i] - 'a';
        i++;
    }
      
    puts(s);
       
    return 0;
}
    
     
/*
       
run:
       
THE LAST LINE OF CODE

*/

 



answered Jan 29, 2016 by avibootz

Related questions

...