Char Pointer Practical Example Using String Input and String/Char Variable Passing

code:

#include<stdio.h>
void toggleChar(char *sptr){

    int i;
    for(i=0;*(sptr+i)!='\0';i++)
    {
        if(*(sptr+i)>='a' && *(sptr+i)<='z')
            *(sptr+i)=*(sptr+i)-32;
        else if(*(sptr+i)>='A'&& sptr[i]<='Z')
            *(sptr+i)=*(sptr+i)+32;
    }

}
int main()
{
    char str[2000];
    scanf("%[^\n]",str);
    toggleChar(str);
    printf("%s",str);

    return 0;
}

Theory:

 

 

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published. Required fields are marked *