Strings in C Language

 // Online C compiler to run C program online

#include <stdio.h>

#include<string.h>

#include<ctype.h>


int main() {

    // Write C code here

    // char str[]={'G','u','n','j','a','n','\0'};

    // char str[]={'G','u','n','j','a','n'};

    // char str[]={"Gunjan"};

    // char str[]="Gunjan";

    // char str[6]="Gunjan";

    // char str[5]="Gunjan"; // will throw an error

    // char str[7]="Gunjan";

    // char str[]="Gunjan";

    // printf("%s\n",str);

    char str[20];

    printf("Enter the value of the string:-\n");

    // scanf("%s",&str); // cannot read spaces and eliminates the string after space.

    fgets(str,sizeof(str),stdin);

    

    

    printf("%s",str);

    str[3]='n';

    printf("%c\n",str[3]);

    printf("%s",str);

    printf("The length of the string is %d\n",strlen(str));

    

    char f[]="Apple";

    char s[]="Apple";

    printf("%c\n",toupper(f[3]));

    printf("%c\n",tolower(f[3]));

    printf("%d\n",strcmp(f,s));

    // char *ptr="Gunjan";

    // for(int i=0;*(ptr+i)!='\0';i++){

    //     printf("%c\n",*(ptr+i));

    // }

    

    // 0 → equal

    // Negative → first string is lexicographically smaller

    // Positive → first string is lexicographically larger

    

    

    // char src[]="Hello";

    // char dest[]="World";

    // // strcat(src,dest); // concatenates the string

    // strncat(src,dest,3); // concatenates only a specified charcter

    // printf("%s\n",src); // src contains the concatenated string

    

    // char source[]="Nayak";

    // char destination[20];

    // printf("%s\n",destination);

    // strcpy(destination,source); // copies source to destination

    // strncpy(destination,source,3); // copies only specified character

    // printf("%s\n",destination);

    // for(int i=0;destination[i]!='\0';i++){

    //     printf("%c\n",destination[i]);

    // }


    return 0;

}

Comments

Popular posts from this blog

Requests and Urllib

Dictionary in Python