Format and parse datetime in C

Поделиться
HTML-код
  • Опубликовано: 26 янв 2023
  • Source code can be found here:
    code-vault.net/lesson/242e8f1...
    ===== Support us through our store =====
    code-vault.net/shop
    ===== Check out our website =====
    code-vault.net
    ===== Check out our Discord server =====
    discord.code-vault.net

Комментарии • 16

  • @2000luisinha
    @2000luisinha 8 месяцев назад

    I have a c code with 4 different variables, each one with a different timestamp. I've tried to use strcpy and ctime_r, but none of them allows me to have different values for the timestamps. When one of them gets updated, the other timestamps also get updated, even though they are inside if's and have different names. Is there any sollution for my problem?

    • @2000luisinha
      @2000luisinha 8 месяцев назад

      for some reason, now it is working😅 anyways, the strcpy worked fine!

  • @mehregankbi
    @mehregankbi Год назад

    can we have videos about how in linux, processes don't really exists and units of exection are rather threads and thread groups? in particular the clone() syscall and how fork is a subset of clone. that'd be really lovely

  • @robertocruz5045
    @robertocruz5045 Год назад

    doubt:
    A program in the language c, that does the following:
    of a file A and a file B.
    From file A it will read each row and each value in the row will assign it to a variable, except the first one which will assign it to an array. The first row will contain from 1 to n values, separated by the tab and that will be an array which will be a counter to do the following:
    The entire contents of file B will be read and assigned to a variable, for example: variable Bfile .
    For each element of the matrix, a text will be replaced inside the Bfile variable, and a file will be created for each element of the matrix.
    example:
    file A:
    dataone \t datatwo \t datathree
    value2
    value3
    value4
    value5
    B-file
    foo foo foo Datartoreplace1 foo foo foo Datarepalce2 foo foo foo Datarepalce3 foo foo Datarepalce4 foo foo Datareplace5
    Process
    step one .- Read all the contents of file B and assign it to a variable, called Bfile.
    step two.- read file A, create an array with the data from row 1 with the name arrayElements (in the example it is an array of three elements).
    step three.- Assign the value of the second row of file A to the variable ReplaceValue1.
    step three.- Assign the value of the third row of file A to the variable ReplaceValue2.
    step three.- Assign the value of the fourth row of file A to the variable ReplaceValue3.
    step three.- Assign the value of the fifth row of file A to the variable ReplaceValue4.
    step four.- for each element of the arrayElements array, replace the first element of the array inside the Bfile variable with the text Datartoreplace1; replace the text Datarepalce2 with the variable ReplaceValue1; replace the text Datarepalce3 with the variable ReplaceValue2; replace the text Datarepalce4 with the variable ReplaceValue3; replace the text Datarepalce5 with the variable ReplaceValue4;
    and at the end of the loop, save a text file with the name of the array element, in this case dataone . Do the same for the other elements.

  • @leonardopisano9575
    @leonardopisano9575 Год назад +1

    Is there a way to add symbols while the user is typing? "/", for example. Great video, thank you.

    • @CodeVault
      @CodeVault  Год назад

      That's an interesting question. As far as I am aware it's not possible by simply using the stdin. I will research and, if I find a way, I'll surely make a video on that

  • @lettever801
    @lettever801 Год назад +1

    Hi, is it possible to create a function that accepts different types of data? I have a function in my program and I would like to either accepts an int as an argument or a struct and would want do to different things depending on what data type it is

    • @CodeVault
      @CodeVault  Год назад +1

      Yes it is. You can use void pointers.
      Here's how you could do it for int and string types:
      void f(void* param, int type) {
      if (type == 0) {
      int paramInt = *(int*)param;
      // process param as int
      } else if (type == 1) {
      char* paramString = (char*)param;
      // process param as string
      }
      }
      int main(int argc, char* argv[]) {
      int x = 15;
      f(&x, 0);
      char* str = "Hello world";
      f(str, 1);
      }
      There's a video on the topic of void pointers: code-vault.net/lesson/qon6f2tjor:1603733520405

  • @vilijanac
    @vilijanac Год назад

    Over 80 000 IT employees lost their job this month in big tech, not one could show you a simple log subroutine? Yes, I think so.

  • @NotMarkKnopfler
    @NotMarkKnopfler Год назад

    Why does it return the same time after the two second delay, and how do we get around it?

    • @CodeVault
      @CodeVault  Год назад +1

      You can either use the "_s" or "_r" variants of the functions or simply strcpy the results to strings you have defined locally (one for each call). Something like this:
      char dateString[200];
      strcpy(dateString, ctime(&t));

  • @NotMarkKnopfler
    @NotMarkKnopfler Год назад +1

    You didn't link the video up top 🙂 - but thanks again for a great tutorial 👍

    • @leonardopisano9575
      @leonardopisano9575 Год назад +1

      You never sang with Dire Straits? 😄

    • @CodeVault
      @CodeVault  Год назад

      It should appear at the top... At which timestamp you're referring to?