Working with character arrays and "strings" in C

Поділитися
Вставка
  • Опубліковано 12 січ 2025

КОМЕНТАРІ • 44

  • @nobantahir
    @nobantahir 4 роки тому +47

    you're saving me from a professor who can't teach so I'm gonna watch all the ads I need to I love you

  • @aj-sk2nf
    @aj-sk2nf 2 роки тому +2

    in less than 6 minutes you taught me more about C and strings in C than i ever learned in a full semester on C programming. thank you, @EngineerMan!!

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

    Thank you! Easy to understand as a beginner and straight to the point

  • @remotetechie6910
    @remotetechie6910 5 років тому +3

    Amazing content, great explanations. I love those short but really good comments for every code line!

  • @shailendrakunwar6079
    @shailendrakunwar6079 7 років тому +3

    Very precise an informative video .Thank you for uploading and hoping to see further more videos like this.

  • @mikobrown2953
    @mikobrown2953 4 роки тому +1

    Incredible, short and easy to understand. Thank you!

  • @devinramsden5412
    @devinramsden5412 5 років тому +1

    Great vids for brushing up on c before some classes, much love brother

  • @Mike-gs7eo
    @Mike-gs7eo 7 років тому +7

    Great explanation. Would appreciate something on structs if possible, in particular use of the flexible array member (unsized last element in struct). thanks

    • @EngineerMan
      @EngineerMan  7 років тому +2

      Will add it to pending video list!

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

    Dude this is so trippy coming from Java, thank you!

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

    you explained more about strings in 6 minutes than my teacher did in the whole semester...

  • @EchoVids2u
    @EchoVids2u 5 років тому

    Best explanation so far on c strings. Thanks

  • @bishtss1
    @bishtss1 3 роки тому

    Nice content full of information. Thanks clearing the doubts.

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

    Engineer bro I want to thank you so much you need to teach I mean that! I had 2 eureka moments watch this video!

  • @dan.franco
    @dan.franco 8 місяців тому

    This video is really good! Thank you!

  • @vanniyasingamsivasayanth3629
    @vanniyasingamsivasayanth3629 4 роки тому

    Beautiful. Simple and Elegant.

  • @pwlegolas3
    @pwlegolas3 5 років тому

    thank you engineer man... Your videos help a lot !

  • @RussTeeTrombone
    @RussTeeTrombone 6 років тому

    Awesome and succinct. Thanks a ton for these.

  • @simonmarabi2661
    @simonmarabi2661 3 роки тому

    really good introductoy video

  • @shibah9345
    @shibah9345 3 роки тому

    To print integer arrays, we would normally need a loop and some variable to move through the indices, one after the other.
    But why isn't this the case with character arrays? Why do we just type the array variable name and everything works fine?

  • @chantelleboutin
    @chantelleboutin 7 років тому

    Succinct and to the point. Very educational.
    Here's a challenge, using Git to control a solo project from multiple computers. Git still seems nebulous and complex. Maybe you can show us how with no time a wasting.

    • @EngineerMan
      @EngineerMan  7 років тому

      Craig Faas I love Git! I could certainly do that.

    • @amlamarra
      @amlamarra 7 років тому

      That's exactly what I use git for and is the easier aspect of it. You just need 4 commands, git commit, git add, git pull, and git push. Now getting into branches, pull requests, releases, tagging, etc; that's the hard part.

  • @kelechistewart2133
    @kelechistewart2133 7 років тому +2

    Thanks for another helpful video! Could you possibly do one on creating different structures in C, for example a Binary Tree?

    • @EngineerMan
      @EngineerMan  7 років тому +3

      Yeah, I can definitely look at doing that!

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

    to the point, no BS. respect.

  • @andydelle4509
    @andydelle4509 5 років тому

    Isn't the NULL byte '/0' the same as 0 or zero? I have successfully used a plain zero to terminate strings in C. Is that just a compiler specific (Boreland 4.5) exception?

    • @EngineerMan
      @EngineerMan  5 років тому

      I'm thinking so. If a 0 could be substituted in place of a null byte, how would one have a string with a 0 in it?

    • @andydelle4509
      @andydelle4509 5 років тому

      @@EngineerMan Well say you want to truncate a string to 6 bytes max, in this case six ASCII characters. I just plug a zero into the str_array[6] position. That effectively chops it off. Now as I said this works with the old Boreland C compliers including 4.5. I'm not sure if this is a legal C practice?
      char s1[[16];
      strcpy (s1, "HelloWorld");
      s1[6]= 0;
      printf("%s",s1);
      result: HelloW

    • @davez5201
      @davez5201 9 місяців тому

      ​@andydelle4509 4 years late, but just so you know: 0 is an int, \0 is a char. They are functionally the same. So int 0 == char \0 BUT char 0 != char \0. Makes sense?

    • @andydelle4509
      @andydelle4509 9 місяців тому

      @@davez5201 Yes, thanks.

  • @justin_time
    @justin_time 7 років тому

    Hi Engineer Man! Thank you for posting this video and welcome to UA-cam! In your intro video you said that you like video request so here is one for you... I am trying to create a program in C to load a tab delimited text file, from any folder on my computer(in the future to be input from the user), print the text (strings, I believe) from the text document to the screen, then sort the information based upon a certain column, reprint it to the screen, and then finally save it to a new text file. Can you help me, and everyone else, by showing me how I might go about doing this? This is not for hw/class, it is a personal project.
    Here is what I have so far:
    #include
    #include
    #define N 30
    int main()
    {
    char name[];
    char course[];
    FILE *pointer = fopen("C:\\Users\\Jesse Hight\\Desktop
    \\TutoringCodeFolder\SimplifiedStudentRequests", "r");
    test=fscanf(pointer, "%s,%s",&name[N],&course[N]);
    printf("%s\t%s", name[ ],course[ ]);
    fclose(f);
    /*
    Idea:
    row 1 of array 1 (from the original file)=row 1 of array2.
    search array 1 for a course equal to row 1 of array 2.
    for( )
    if(array1[i][2]==array2[1][3]
    array2[k][L]=array1[i][2]
    k++
    L=3
    else
    search array1 for new subject not equal to current/last row of array2
    new subject from array1=next row of array2
    */
    }
    The original text file looks like:
    Jesse ES 330-01
    John MA 330-01
    Alexa MA 330-01
    Jose FN 361-01
    Dave FN 361-01
    Gabriel ES 330-01
    Steve FN 361-01
    Parker FN 361-01
    Robert FN 361-01
    Caroline ES 330-01
    And I would like the output to be like this, with the list sorted by common classes:
    Jesse ES 330-01
    Caroline ES 330-01
    Gabriel ES 330-01
    John MA 330-01
    Alexa MA 330-01
    Jose FN 361-01
    Dave FN 361-01
    Steve FN 361-01
    Parker FN 361-01
    Robert FN 361-01
    Thank you!

    • @EngineerMan
      @EngineerMan  7 років тому +3

      Let me see if I can create a generic video that teaches people stuff and helps you out.

    • @justin_time
      @justin_time 7 років тому

      Thank you very much!

  • @dominiksusmel
    @dominiksusmel 6 років тому +1

    Great, now do the UTF!

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

    Thnx man ;)

  • @tatogz4819
    @tatogz4819 5 років тому

    I don't know if someone will answer me: how can I save the first character of a string , for example
    char c;
    char * string;
    string="hello";
    c=getc(string); //someone told this could work but it doesn't work
    Please help

    • @EngineerMan
      @EngineerMan  5 років тому +1

      The answer is "string[0]".
      Example:
      #include
      void main(void) {
      char c;
      char *string = "hello";
      c = string[0];
      printf("%c", c);
      }

    • @tatogz4819
      @tatogz4819 5 років тому

      @@EngineerMan thank you so much! Sorry to bother you... and what if a want to give my variable "string" any other value, do I must use scanf?
      char c;
      char *string;
      scanf("%s", string);
      c = string [0];
      printf("%c", c);
      This would be ok?

    • @EngineerMan
      @EngineerMan  5 років тому +1

      Just about. You'll need to allocate space first.

  • @notmyrealID
    @notmyrealID 3 роки тому

    thank you!

  • @erbkgupta8679
    @erbkgupta8679 5 років тому

    Great!

  • @junweili3527
    @junweili3527 3 роки тому

    name[0] *(name + 0) *(0 + name) 0[name]
    werid but fun, :D, thanks