Search
 
SCRIPT & CODE EXAMPLE
 

C

function that changes all lowercase letters of a string to uppercase.

char *string_toupper(char *s)
{
  	int i;
     while( s[i] != '' ) 
     {
        // if character is in lowercase
        // then subtract 32 
        if( s[i] >= 'a' && s[i] <= 'z' )
        {
           s[i] = s[i] - 32;
        }

        // increase iterator variable
        i++;
     }
     return (s);
 }
Comment

onvert it to lower case letter if it’s an upper case letter and convert it to upper case letter if it’s a lower

#include<iostream>
#include<string>
using namespace std; 

int main() 
{ 
    string str="Hello World"; 
    int i;
    
    cout<<"The String is: 
"<<str;
    cout<<endl<<endl;
    
    cout<<"String after uppercase lowercase modification: 
";
    for(i=0; i < str.length(); i++)
    {
        //if its uppercase add to its Ascii code 32 to make lowercase
        if(str[i]>='A' && str[i]<='Z')
      	cout<<char(str[i]+32);
      	
      	// else if its lowercase subtract 32 to make it upper case 
        else if(str[i]>='a' && str[i]<='z')
      	cout<<char(str[i]-32);
      	
      	// else if its a space or symbol for example just print it as is
      	else cout<<str[i];
      	
      	//the reason this works is that the distance in Ascii from uppercase to lowercase 
      	//is standard and constant
    }
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
C :: scan c 
C :: fwrite c 
C :: integer in c 
C :: open a file in from terminal 
C :: how to debug a segmentation fault in c 
C :: size of operator in c language 
C :: c defined value sum 
C :: pointer in c 
C :: Regex to match any character being repeated more than 10 times 
C :: *= in c 
C :: yt derived field 
C :: c atoi atof 
C :: obstacle avoiding robot in c++ program 
C :: spacemacs start server 
C :: print in c 11111 00000 11111 00000 11111 
C :: Fibonacci program c pthread 
C :: how to link flexslider 
C :: ejemplo c holamundo 
C :: how to output in green in c 
C :: arcolinux 
C :: como hacer para que una salida en linux aparezca de poco en poco 
C :: if statement shortcut c 
C :: How to set bit in float number in C 
C :: c bind str and int 
C :: why return 0 is written at the code end? 
C :: what to do after gan training 
C :: how to get a string input in c 
C :: c variable 
C :: how to do add to an integrr in c 
Dart :: navigator.pushandremoveuntil flutter 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =