C string functions 🔠

Поділитися
Вставка
  • Опубліковано 18 жов 2024

КОМЕНТАРІ • 58

  • @BroCodez
    @BroCodez  3 роки тому +38

    #include
    #include

    int main(){

    char string1[] = "Bro";
    char string2[] = "Code";

    strlwr(string1); // converts a string to lowercase
    //strupr(string1); // converts a string to uppercase
    //strcat(string1, string2); // appends string2 to end of string1
    //strncat(string1, string2, 1); // appends n characters from string2 to string1
    //strcpy(string1, string2); // copy string2 to string1
    //strncpy(string1, string2, 2); // copy n characters of string2 to string1

    //strset(string1, '?'); //sets all characters of a string to a given character
    //strnset(string1, 'x', 1); //sets first n characters of a string to a given character
    //strrev(string1); //reverses a string
    //int result = strlen(string1); // returns string length as int
    //int result = strcmp(string1, string2); // string compare all characters
    //int result = strncmp(string1, string2, 1); // string compare n characters
    //int result = strcmpi(string1, string1); // string compare all (ignore case)
    //int result = strnicmp(string1, string1, 1); // string compare n characters (ignore case)
    printf("%s", string1);
    /*
    if(result == 0)
    {
    printf("These strings are the same");
    }
    else
    {
    printf("These strings are not the same");
    }
    */
    return 0;
    }

  • @alameensaleem4158
    @alameensaleem4158 Рік тому +21

    you are so underated

  • @xetycm.8923
    @xetycm.8923 9 місяців тому +11

    I was to so some of the functions (like strlwr, strcmpi, and etc) but for some reason they didn't exist in the string.h library (it kept saying the function doesn't exist). some people suggest that I make these functions myself using other libraries; but is there a way to fix the issue i'm having?

  • @QuimChaos
    @QuimChaos 2 роки тому +19

    strlwr(string) and strupr(string) don't exist in standard c library string.h. you have to have a little fun and create it yourself, by using a loop that calculates the correspondent lower/uppercase char in the ASCII table and replacing it, or usinc ctype.h and tolower()/toupper() functions to convert cases. the same for strset(), strnset(), strrev(), strcmpi() and strnicmp()
    not defining the size of the strings results in stack overflow/stack smashing and unexpected behaviour.
    Examples for string to lowercase/uppercase (this doesn't accept string literals as arguments):
    #include
    char* stringToUpper(char * string){
    int i = 0;
    while (string[i] != '\0'){
    string[i] = (char)toupper(string[i]);
    i++;
    }
    return string;
    }
    char* stringToLower(char * string){
    int i = 0;
    while (string[i] != '\0'){
    string[i] = (char)tolower(string[i]);
    i++;
    }
    return string;
    }

    • @QuimChaos
      @QuimChaos 2 роки тому

      better, much better:
      #include
      #include
      void stringToUpper(char * string){
      while (*string != '\0'){
      *string = (char)toupper(*string);
      string++;
      }
      }
      void stringToLower(char * string){
      while (*string != '\0'){
      *string = (char)tolower(*string);
      string++;
      }
      }
      int main() {
      char string1[50] = "Hello";
      stringToUpper(string1);
      printf("To upper %s
      ", string1);
      stringToLower(string1);
      printf("To lower %s
      ", string1);
      return 0;
      }

    • @gustaw6000
      @gustaw6000 Рік тому +1

      I cannot find those two functions in IBM documentary for C standard libraries, although it works in Visual Studio Code. Maybe they added those function recently?

    • @brisauce6944
      @brisauce6944 Рік тому +1

      Thank you for clarifying this! It's confusing to a new programmer like me when I see things like "implicit declaration of is not valid in c99", despite it being mentioned in a tutorial video. You're a sanity saver man!

    • @Birendra-Chess
      @Birendra-Chess 7 місяців тому +1

      Thank You bro, I Wasted one hour on this.

    • @kennya51
      @kennya51 2 місяці тому +2

      The in MacOS/Linux different of that of the Windows . strlwr(), strupr() are "non-standard", so they only exist in the Windows one, which BroCode is using.

  • @buzzbuzz20xx
    @buzzbuzz20xx 8 днів тому

    Nice video

  • @Ava-x9z3n
    @Ava-x9z3n 2 місяці тому

    Thx so much for the quality c content!

  • @amkhrjee
    @amkhrjee 7 місяців тому

    This tut was goated no cap

  • @Mmaxum
    @Mmaxum Рік тому +1

    Thanks Coo Code, very cool

  • @koushik-ru1zb
    @koushik-ru1zb 4 місяці тому

    superrrr bro
    keep doijng

  • @nonamedelete9132
    @nonamedelete9132 2 роки тому +2

    How can strcat() make string1 bigger without malloc? And I thought that a string created using [] is constant.

  • @toxiclucien8168
    @toxiclucien8168 3 роки тому +5

    first comment here.....and im already a big fan of your channel ty for sharing useful information

    • @SpicaSuzuki
      @SpicaSuzuki 3 роки тому +3

      2nd comment

    • @toxiclucien8168
      @toxiclucien8168 3 роки тому +1

      @@SpicaSuzuki which language you are learning?

    • @SpicaSuzuki
      @SpicaSuzuki 3 роки тому +1

      @@toxiclucien8168 c is my first language (except shell. idk shell that much but i use linux). i'm learning c rn. i came here to copy paste the code. You?

    • @toxiclucien8168
      @toxiclucien8168 3 роки тому +1

      @@SpicaSuzuki I'm currently learning C in my university so fam here to copy the code .....I have completed the whole video and now I can create any program which I'm told to....(except for the maths one coz I need to revise my maths formula for it)...but other than that I also made 3 games with Brocode help

    • @toxiclucien8168
      @toxiclucien8168 3 роки тому +1

      @@SpicaSuzuki he's a great UA-camr...quite underrated

  • @muchkoniabouttown6997
    @muchkoniabouttown6997 2 місяці тому

    Holy crap thanks bro!

  • @Dbsmart182
    @Dbsmart182 4 місяці тому +8

    Who are here before exam 😂😂

  • @haseebkahn4811
    @haseebkahn4811 Рік тому

    Thank you ❤️

  • @kurisey8020
    @kurisey8020 Рік тому +2

    What does case sensitivity mean?

    • @akeem3127
      @akeem3127 Рік тому +3

      Upper vs upper, if the first was a variable and you try to print with a second it would give and error

  • @yamilaxus
    @yamilaxus 2 роки тому

    AWESOME!

  • @tejusc1568
    @tejusc1568 2 роки тому +1

    Sir, strupr and strlwr both these functions aren't working even after including string header file. How to fix it

    • @trungdu9354
      @trungdu9354 2 роки тому +1

      Looked up source of didn't see them function in there so to fix had to manually write a internal code inside code, or could make my own newfunction.c file and import it there since going use it often (Put these 2 codes above your int main() not inside it)
      //Beginner Version strlwr()
      char * strlwr(char * s){
      char *t = s;
      if (!s){
      return 0;
      }
      int i = 0;
      while ( *t != '\0' ){
      if (*t >= 'A' && *t = 'a' && *t

  • @delright6829
    @delright6829 Рік тому +1

    im little bit confused everything here works besides strset,strnset and strrev vs isnt recognizing them. i believe theyre not included in string.h and stdio.h is there a fix to it ? im writing my exam next week and were only allowed to use libraries we got shown example: bool etc aint allowed.

    • @farisraid7588
      @farisraid7588 Рік тому

      ask chat gpt questions like this thats what im doing when my code doesnt work and idk why

    • @delright6829
      @delright6829 Рік тому

      @@farisraid7588 thats what i did in the end but thanks for the tip

  • @mohammedisarezwani
    @mohammedisarezwani Рік тому +1

    how can we remember all these functions ?

    • @Mr.noname_
      @Mr.noname_ 11 місяців тому

      by taking notes my dear haha

    • @zraie2455
      @zraie2455 10 місяців тому +2

      You don't need to remember all these functions! You can pretty much write code using your knowledge so far that accomplishes what these functions do. Knowing these functions just makes it easier for you to write code as you won't have to write new functions in your code with a specific purpose if you remember that there's a library which already does that. I.e. you won't have to create an pow(x, y) function in your program if you remember that math.h has a library with a similar function.

  • @hamidabduljaabbar8419
    @hamidabduljaabbar8419 Рік тому +1

    anyone knows why the result of my strcat(string1, string2) is BroCdee? im using linux mint distro

  • @unikneupane01
    @unikneupane01 Рік тому

    Broo😢 I came for string token where that at😭😭

  • @jerileiconcepcion3866
    @jerileiconcepcion3866 2 роки тому

    most of these functions aren't working on my mac. any idea how to fix this?

    • @_____Shadow_____
      @_____Shadow_____ 2 роки тому

      Did you use the library?

    • @tituskace5566
      @tituskace5566 2 роки тому

      @@_____Shadow_____ yes, i did. still, it didn't work.

    • @bower19942
      @bower19942 2 роки тому

      it would help if you share which error did you get when you tried to run em

    • @collin7776
      @collin7776 2 роки тому +3

      @@tituskace5566 So the strlwr and strupr along with some other functions listed in this video are part of the Microsoft implementation of C. Mac/linux/unix have to use different functions to alter strings. You can either use the ctype.h or code the functions yourself.

  • @LunarProjectND
    @LunarProjectND 3 місяці тому

    bro code u didn't cover strlen function

  • @dvarshanidze
    @dvarshanidze 7 місяців тому

    CooCode

  • @RedR-r2j
    @RedR-r2j Місяць тому

    these functions are not working in mac os

  • @junaiid0104
    @junaiid0104 Рік тому

    hello sir the strings functions are not working on my MacBook Pro ! what do I do ?? please help me out !!!!

  • @naveenkumar1853
    @naveenkumar1853 10 місяців тому

    😢