C - accessing a structure array









up vote
3
down vote

favorite












I'm trying to code my own Turing machine. My program takes two files as arguments: my initial tape the machine will have to work with, and a rule file. This rule file consists in one rule per line, and each rule is five integers: current state, symbol found, new symbol, direction for the head to go, and new state. For that, I have a function that reads my file and puts each set of five ints found in a rule structure. An array of these structures is then generated.



What I'm trying to do is to return this array in order to be able to use it later on. Here is what I have :



struct rule 
int cur_state;
int symbol;
int new_symbol;
int direction;
int new_state;
;
typedef struct rule rule;
struct vect
int nb_elem;
rule *p;
;

vect rule_generator (char * file_rule)
int line_number = 0;
int ligne;
char tmp;
rule rule_list[line_number];
vect output_rules;
FILE * file;
file = fopen(file_rule, "r");

for(tmp = getc(file); tmp != EOF; tmp = getc(file))
if ( tmp == 'n')
line_number++;

output_rules.p = malloc(line_number*sizeof(rule));
assert(output_rules.p);
output_rules.nb_elem = line_number;
for (ligne = 0; ligne < line_number; ligne++ )
fscanf(file, "%d %d %d %d %d", &rule_list[ligne].cur_state,
&rule_list[ligne].symbol, &rule_list[ligne].new_symbol,
&rule_list[ligne].direction, &rule_list[ligne].new_state);


fclose(file);
return output_rules;

int main (int argc, char *argv)
vect rule_list = rule_generator(argv[2]);
printf("symbole : %ls n", &rule_list.p[0].symbol);
return 0;



As some of you may already have guessed, this doesn't print anything... I've been scratching my head for a while, trying to access my array. I could really use a hand here!










share|improve this question









New contributor




Bruh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.























    up vote
    3
    down vote

    favorite












    I'm trying to code my own Turing machine. My program takes two files as arguments: my initial tape the machine will have to work with, and a rule file. This rule file consists in one rule per line, and each rule is five integers: current state, symbol found, new symbol, direction for the head to go, and new state. For that, I have a function that reads my file and puts each set of five ints found in a rule structure. An array of these structures is then generated.



    What I'm trying to do is to return this array in order to be able to use it later on. Here is what I have :



    struct rule 
    int cur_state;
    int symbol;
    int new_symbol;
    int direction;
    int new_state;
    ;
    typedef struct rule rule;
    struct vect
    int nb_elem;
    rule *p;
    ;

    vect rule_generator (char * file_rule)
    int line_number = 0;
    int ligne;
    char tmp;
    rule rule_list[line_number];
    vect output_rules;
    FILE * file;
    file = fopen(file_rule, "r");

    for(tmp = getc(file); tmp != EOF; tmp = getc(file))
    if ( tmp == 'n')
    line_number++;

    output_rules.p = malloc(line_number*sizeof(rule));
    assert(output_rules.p);
    output_rules.nb_elem = line_number;
    for (ligne = 0; ligne < line_number; ligne++ )
    fscanf(file, "%d %d %d %d %d", &rule_list[ligne].cur_state,
    &rule_list[ligne].symbol, &rule_list[ligne].new_symbol,
    &rule_list[ligne].direction, &rule_list[ligne].new_state);


    fclose(file);
    return output_rules;

    int main (int argc, char *argv)
    vect rule_list = rule_generator(argv[2]);
    printf("symbole : %ls n", &rule_list.p[0].symbol);
    return 0;



    As some of you may already have guessed, this doesn't print anything... I've been scratching my head for a while, trying to access my array. I could really use a hand here!










    share|improve this question









    New contributor




    Bruh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      I'm trying to code my own Turing machine. My program takes two files as arguments: my initial tape the machine will have to work with, and a rule file. This rule file consists in one rule per line, and each rule is five integers: current state, symbol found, new symbol, direction for the head to go, and new state. For that, I have a function that reads my file and puts each set of five ints found in a rule structure. An array of these structures is then generated.



      What I'm trying to do is to return this array in order to be able to use it later on. Here is what I have :



      struct rule 
      int cur_state;
      int symbol;
      int new_symbol;
      int direction;
      int new_state;
      ;
      typedef struct rule rule;
      struct vect
      int nb_elem;
      rule *p;
      ;

      vect rule_generator (char * file_rule)
      int line_number = 0;
      int ligne;
      char tmp;
      rule rule_list[line_number];
      vect output_rules;
      FILE * file;
      file = fopen(file_rule, "r");

      for(tmp = getc(file); tmp != EOF; tmp = getc(file))
      if ( tmp == 'n')
      line_number++;

      output_rules.p = malloc(line_number*sizeof(rule));
      assert(output_rules.p);
      output_rules.nb_elem = line_number;
      for (ligne = 0; ligne < line_number; ligne++ )
      fscanf(file, "%d %d %d %d %d", &rule_list[ligne].cur_state,
      &rule_list[ligne].symbol, &rule_list[ligne].new_symbol,
      &rule_list[ligne].direction, &rule_list[ligne].new_state);


      fclose(file);
      return output_rules;

      int main (int argc, char *argv)
      vect rule_list = rule_generator(argv[2]);
      printf("symbole : %ls n", &rule_list.p[0].symbol);
      return 0;



      As some of you may already have guessed, this doesn't print anything... I've been scratching my head for a while, trying to access my array. I could really use a hand here!










      share|improve this question









      New contributor




      Bruh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I'm trying to code my own Turing machine. My program takes two files as arguments: my initial tape the machine will have to work with, and a rule file. This rule file consists in one rule per line, and each rule is five integers: current state, symbol found, new symbol, direction for the head to go, and new state. For that, I have a function that reads my file and puts each set of five ints found in a rule structure. An array of these structures is then generated.



      What I'm trying to do is to return this array in order to be able to use it later on. Here is what I have :



      struct rule 
      int cur_state;
      int symbol;
      int new_symbol;
      int direction;
      int new_state;
      ;
      typedef struct rule rule;
      struct vect
      int nb_elem;
      rule *p;
      ;

      vect rule_generator (char * file_rule)
      int line_number = 0;
      int ligne;
      char tmp;
      rule rule_list[line_number];
      vect output_rules;
      FILE * file;
      file = fopen(file_rule, "r");

      for(tmp = getc(file); tmp != EOF; tmp = getc(file))
      if ( tmp == 'n')
      line_number++;

      output_rules.p = malloc(line_number*sizeof(rule));
      assert(output_rules.p);
      output_rules.nb_elem = line_number;
      for (ligne = 0; ligne < line_number; ligne++ )
      fscanf(file, "%d %d %d %d %d", &rule_list[ligne].cur_state,
      &rule_list[ligne].symbol, &rule_list[ligne].new_symbol,
      &rule_list[ligne].direction, &rule_list[ligne].new_state);


      fclose(file);
      return output_rules;

      int main (int argc, char *argv)
      vect rule_list = rule_generator(argv[2]);
      printf("symbole : %ls n", &rule_list.p[0].symbol);
      return 0;



      As some of you may already have guessed, this doesn't print anything... I've been scratching my head for a while, trying to access my array. I could really use a hand here!







      c arrays struct






      share|improve this question









      New contributor




      Bruh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      Bruh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited Nov 10 at 15:45









      Greenonline

      97621424




      97621424






      New contributor




      Bruh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Nov 10 at 12:14









      Bruh

      183




      183




      New contributor




      Bruh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Bruh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Bruh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          Few problems here.




          1. You are declaring array with size 0.



            int line_number = 0;
            rule rule_list[line_number];



            You don't need rule_list just remove it.



          2. output_rules is no where being initilized other than memory allocating.


          Solution:



          I would suggest you to use output_rules for fscanf.



          for (ligne = 0; ligne < line_number; ligne++ )
          fscanf(file, "%d %d %d %d %d", &output_rules.p[ligne].cur_state,
          &output_rules.p[ligne].symbol, &output_rules.p[ligne].new_symbol,
          &output_rules.p[ligne].direction, &output_rules.p[ligne].new_state);




          Also did you mean to print the value of symbol?



          As you are using %ls which is used to wchar_t *.



          printf("symbole : %ls n", &rule_list.p[0].symbol);


          should be



          printf("symbole : %d n", rule_list.p[0].symbol);





          share|improve this answer






















          • Totally worked, thank you so much ! Looks like I kinda messed up in variable declarations here lol.
            – Bruh
            Nov 10 at 13:54

















          up vote
          1
          down vote













          There's lots going on here.



          The main problem seems to be that this loop:



          for(tmp = getc(file); tmp != EOF; tmp = getc(file))
          if ( tmp == 'n')
          line_number++;



          is going right the way through the file to the end, which means there's nothing left for fscanf() to read. If you want to read the whole file through once to find out the number of lines, and then read it again to read the content, you're going to have to either a) close and reopen it, or b) use the rewind() or fseek() function to go back to the start of the file.



          (To be honest, an even better solution would be to design your code so that you don't need to read the file twice over. If you end up trying this and get stuck, ask again with a new question on this site.)



          In addition, you should add these lines at the beginning of your code:



          #include <stdio.h>
          #include <stdlib.h>
          #include <assert.h>


          to read in the header files which define the functions you're using, and put this line after your struct vect definition to define the type:



          typedef struct vect vect;


          Also, please run your compiler with warnings enabled. This would have helped you find some of these problems yourself!






          share|improve this answer




















          • Hi thanks for your answer ! For the includes, I didn't put them here on purpose, in order to give you guys something a bit cleaner to look at. I didn't know I had to rewind the pointer, I guess that makes sense, you make me feel dumb lol, thank you so much ! Also, as for typedef : struct vect vect; I seem to have forgotten to copy/paste it from my code, my bad :D
            – Bruh
            Nov 10 at 13:52











          • @Bruh Glad that helps! For next time you ask a question, please reduce your code to as little as possible which shows the problem, and then post all that code. This way bits which you don't know are important are included, and we don't have to guess which bits you're showing us, and which bits yo're not. There's some really helpful advice on that here: stackoverflow.com/help/mcve And don't feel dumb - everyone starts somewhere! Good luck!
            – Tim
            Nov 10 at 14:17











          • Lastly, remember that if you like this answer and the other answer on this page, or in fact any answer on the site, you can click the "up" arrow to vote for them as "useful answers".
            – Tim
            Nov 10 at 14:21










          • it says I have a too low reputation so it doesnt display my vote :p i guess i need to be more active
            – Bruh
            Nov 11 at 11:50










          • @Bruh My mistake. You need fifteen reputation to vote up. There you go, now you have it. :-) stackoverflow.com/help/privileges
            – Tim
            Nov 11 at 12:04










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          Bruh is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238846%2fc-accessing-a-structure-array%23new-answer', 'question_page');

          );

          Post as a guest






























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          Few problems here.




          1. You are declaring array with size 0.



            int line_number = 0;
            rule rule_list[line_number];



            You don't need rule_list just remove it.



          2. output_rules is no where being initilized other than memory allocating.


          Solution:



          I would suggest you to use output_rules for fscanf.



          for (ligne = 0; ligne < line_number; ligne++ )
          fscanf(file, "%d %d %d %d %d", &output_rules.p[ligne].cur_state,
          &output_rules.p[ligne].symbol, &output_rules.p[ligne].new_symbol,
          &output_rules.p[ligne].direction, &output_rules.p[ligne].new_state);




          Also did you mean to print the value of symbol?



          As you are using %ls which is used to wchar_t *.



          printf("symbole : %ls n", &rule_list.p[0].symbol);


          should be



          printf("symbole : %d n", rule_list.p[0].symbol);





          share|improve this answer






















          • Totally worked, thank you so much ! Looks like I kinda messed up in variable declarations here lol.
            – Bruh
            Nov 10 at 13:54














          up vote
          1
          down vote



          accepted










          Few problems here.




          1. You are declaring array with size 0.



            int line_number = 0;
            rule rule_list[line_number];



            You don't need rule_list just remove it.



          2. output_rules is no where being initilized other than memory allocating.


          Solution:



          I would suggest you to use output_rules for fscanf.



          for (ligne = 0; ligne < line_number; ligne++ )
          fscanf(file, "%d %d %d %d %d", &output_rules.p[ligne].cur_state,
          &output_rules.p[ligne].symbol, &output_rules.p[ligne].new_symbol,
          &output_rules.p[ligne].direction, &output_rules.p[ligne].new_state);




          Also did you mean to print the value of symbol?



          As you are using %ls which is used to wchar_t *.



          printf("symbole : %ls n", &rule_list.p[0].symbol);


          should be



          printf("symbole : %d n", rule_list.p[0].symbol);





          share|improve this answer






















          • Totally worked, thank you so much ! Looks like I kinda messed up in variable declarations here lol.
            – Bruh
            Nov 10 at 13:54












          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          Few problems here.




          1. You are declaring array with size 0.



            int line_number = 0;
            rule rule_list[line_number];



            You don't need rule_list just remove it.



          2. output_rules is no where being initilized other than memory allocating.


          Solution:



          I would suggest you to use output_rules for fscanf.



          for (ligne = 0; ligne < line_number; ligne++ )
          fscanf(file, "%d %d %d %d %d", &output_rules.p[ligne].cur_state,
          &output_rules.p[ligne].symbol, &output_rules.p[ligne].new_symbol,
          &output_rules.p[ligne].direction, &output_rules.p[ligne].new_state);




          Also did you mean to print the value of symbol?



          As you are using %ls which is used to wchar_t *.



          printf("symbole : %ls n", &rule_list.p[0].symbol);


          should be



          printf("symbole : %d n", rule_list.p[0].symbol);





          share|improve this answer














          Few problems here.




          1. You are declaring array with size 0.



            int line_number = 0;
            rule rule_list[line_number];



            You don't need rule_list just remove it.



          2. output_rules is no where being initilized other than memory allocating.


          Solution:



          I would suggest you to use output_rules for fscanf.



          for (ligne = 0; ligne < line_number; ligne++ )
          fscanf(file, "%d %d %d %d %d", &output_rules.p[ligne].cur_state,
          &output_rules.p[ligne].symbol, &output_rules.p[ligne].new_symbol,
          &output_rules.p[ligne].direction, &output_rules.p[ligne].new_state);




          Also did you mean to print the value of symbol?



          As you are using %ls which is used to wchar_t *.



          printf("symbole : %ls n", &rule_list.p[0].symbol);


          should be



          printf("symbole : %d n", rule_list.p[0].symbol);






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 10 at 12:44

























          answered Nov 10 at 12:35









          kiran Biradar

          3,8472726




          3,8472726











          • Totally worked, thank you so much ! Looks like I kinda messed up in variable declarations here lol.
            – Bruh
            Nov 10 at 13:54
















          • Totally worked, thank you so much ! Looks like I kinda messed up in variable declarations here lol.
            – Bruh
            Nov 10 at 13:54















          Totally worked, thank you so much ! Looks like I kinda messed up in variable declarations here lol.
          – Bruh
          Nov 10 at 13:54




          Totally worked, thank you so much ! Looks like I kinda messed up in variable declarations here lol.
          – Bruh
          Nov 10 at 13:54












          up vote
          1
          down vote













          There's lots going on here.



          The main problem seems to be that this loop:



          for(tmp = getc(file); tmp != EOF; tmp = getc(file))
          if ( tmp == 'n')
          line_number++;



          is going right the way through the file to the end, which means there's nothing left for fscanf() to read. If you want to read the whole file through once to find out the number of lines, and then read it again to read the content, you're going to have to either a) close and reopen it, or b) use the rewind() or fseek() function to go back to the start of the file.



          (To be honest, an even better solution would be to design your code so that you don't need to read the file twice over. If you end up trying this and get stuck, ask again with a new question on this site.)



          In addition, you should add these lines at the beginning of your code:



          #include <stdio.h>
          #include <stdlib.h>
          #include <assert.h>


          to read in the header files which define the functions you're using, and put this line after your struct vect definition to define the type:



          typedef struct vect vect;


          Also, please run your compiler with warnings enabled. This would have helped you find some of these problems yourself!






          share|improve this answer




















          • Hi thanks for your answer ! For the includes, I didn't put them here on purpose, in order to give you guys something a bit cleaner to look at. I didn't know I had to rewind the pointer, I guess that makes sense, you make me feel dumb lol, thank you so much ! Also, as for typedef : struct vect vect; I seem to have forgotten to copy/paste it from my code, my bad :D
            – Bruh
            Nov 10 at 13:52











          • @Bruh Glad that helps! For next time you ask a question, please reduce your code to as little as possible which shows the problem, and then post all that code. This way bits which you don't know are important are included, and we don't have to guess which bits you're showing us, and which bits yo're not. There's some really helpful advice on that here: stackoverflow.com/help/mcve And don't feel dumb - everyone starts somewhere! Good luck!
            – Tim
            Nov 10 at 14:17











          • Lastly, remember that if you like this answer and the other answer on this page, or in fact any answer on the site, you can click the "up" arrow to vote for them as "useful answers".
            – Tim
            Nov 10 at 14:21










          • it says I have a too low reputation so it doesnt display my vote :p i guess i need to be more active
            – Bruh
            Nov 11 at 11:50










          • @Bruh My mistake. You need fifteen reputation to vote up. There you go, now you have it. :-) stackoverflow.com/help/privileges
            – Tim
            Nov 11 at 12:04














          up vote
          1
          down vote













          There's lots going on here.



          The main problem seems to be that this loop:



          for(tmp = getc(file); tmp != EOF; tmp = getc(file))
          if ( tmp == 'n')
          line_number++;



          is going right the way through the file to the end, which means there's nothing left for fscanf() to read. If you want to read the whole file through once to find out the number of lines, and then read it again to read the content, you're going to have to either a) close and reopen it, or b) use the rewind() or fseek() function to go back to the start of the file.



          (To be honest, an even better solution would be to design your code so that you don't need to read the file twice over. If you end up trying this and get stuck, ask again with a new question on this site.)



          In addition, you should add these lines at the beginning of your code:



          #include <stdio.h>
          #include <stdlib.h>
          #include <assert.h>


          to read in the header files which define the functions you're using, and put this line after your struct vect definition to define the type:



          typedef struct vect vect;


          Also, please run your compiler with warnings enabled. This would have helped you find some of these problems yourself!






          share|improve this answer




















          • Hi thanks for your answer ! For the includes, I didn't put them here on purpose, in order to give you guys something a bit cleaner to look at. I didn't know I had to rewind the pointer, I guess that makes sense, you make me feel dumb lol, thank you so much ! Also, as for typedef : struct vect vect; I seem to have forgotten to copy/paste it from my code, my bad :D
            – Bruh
            Nov 10 at 13:52











          • @Bruh Glad that helps! For next time you ask a question, please reduce your code to as little as possible which shows the problem, and then post all that code. This way bits which you don't know are important are included, and we don't have to guess which bits you're showing us, and which bits yo're not. There's some really helpful advice on that here: stackoverflow.com/help/mcve And don't feel dumb - everyone starts somewhere! Good luck!
            – Tim
            Nov 10 at 14:17











          • Lastly, remember that if you like this answer and the other answer on this page, or in fact any answer on the site, you can click the "up" arrow to vote for them as "useful answers".
            – Tim
            Nov 10 at 14:21










          • it says I have a too low reputation so it doesnt display my vote :p i guess i need to be more active
            – Bruh
            Nov 11 at 11:50










          • @Bruh My mistake. You need fifteen reputation to vote up. There you go, now you have it. :-) stackoverflow.com/help/privileges
            – Tim
            Nov 11 at 12:04












          up vote
          1
          down vote










          up vote
          1
          down vote









          There's lots going on here.



          The main problem seems to be that this loop:



          for(tmp = getc(file); tmp != EOF; tmp = getc(file))
          if ( tmp == 'n')
          line_number++;



          is going right the way through the file to the end, which means there's nothing left for fscanf() to read. If you want to read the whole file through once to find out the number of lines, and then read it again to read the content, you're going to have to either a) close and reopen it, or b) use the rewind() or fseek() function to go back to the start of the file.



          (To be honest, an even better solution would be to design your code so that you don't need to read the file twice over. If you end up trying this and get stuck, ask again with a new question on this site.)



          In addition, you should add these lines at the beginning of your code:



          #include <stdio.h>
          #include <stdlib.h>
          #include <assert.h>


          to read in the header files which define the functions you're using, and put this line after your struct vect definition to define the type:



          typedef struct vect vect;


          Also, please run your compiler with warnings enabled. This would have helped you find some of these problems yourself!






          share|improve this answer












          There's lots going on here.



          The main problem seems to be that this loop:



          for(tmp = getc(file); tmp != EOF; tmp = getc(file))
          if ( tmp == 'n')
          line_number++;



          is going right the way through the file to the end, which means there's nothing left for fscanf() to read. If you want to read the whole file through once to find out the number of lines, and then read it again to read the content, you're going to have to either a) close and reopen it, or b) use the rewind() or fseek() function to go back to the start of the file.



          (To be honest, an even better solution would be to design your code so that you don't need to read the file twice over. If you end up trying this and get stuck, ask again with a new question on this site.)



          In addition, you should add these lines at the beginning of your code:



          #include <stdio.h>
          #include <stdlib.h>
          #include <assert.h>


          to read in the header files which define the functions you're using, and put this line after your struct vect definition to define the type:



          typedef struct vect vect;


          Also, please run your compiler with warnings enabled. This would have helped you find some of these problems yourself!







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 10 at 13:11









          Tim

          7,7082344




          7,7082344











          • Hi thanks for your answer ! For the includes, I didn't put them here on purpose, in order to give you guys something a bit cleaner to look at. I didn't know I had to rewind the pointer, I guess that makes sense, you make me feel dumb lol, thank you so much ! Also, as for typedef : struct vect vect; I seem to have forgotten to copy/paste it from my code, my bad :D
            – Bruh
            Nov 10 at 13:52











          • @Bruh Glad that helps! For next time you ask a question, please reduce your code to as little as possible which shows the problem, and then post all that code. This way bits which you don't know are important are included, and we don't have to guess which bits you're showing us, and which bits yo're not. There's some really helpful advice on that here: stackoverflow.com/help/mcve And don't feel dumb - everyone starts somewhere! Good luck!
            – Tim
            Nov 10 at 14:17











          • Lastly, remember that if you like this answer and the other answer on this page, or in fact any answer on the site, you can click the "up" arrow to vote for them as "useful answers".
            – Tim
            Nov 10 at 14:21










          • it says I have a too low reputation so it doesnt display my vote :p i guess i need to be more active
            – Bruh
            Nov 11 at 11:50










          • @Bruh My mistake. You need fifteen reputation to vote up. There you go, now you have it. :-) stackoverflow.com/help/privileges
            – Tim
            Nov 11 at 12:04
















          • Hi thanks for your answer ! For the includes, I didn't put them here on purpose, in order to give you guys something a bit cleaner to look at. I didn't know I had to rewind the pointer, I guess that makes sense, you make me feel dumb lol, thank you so much ! Also, as for typedef : struct vect vect; I seem to have forgotten to copy/paste it from my code, my bad :D
            – Bruh
            Nov 10 at 13:52











          • @Bruh Glad that helps! For next time you ask a question, please reduce your code to as little as possible which shows the problem, and then post all that code. This way bits which you don't know are important are included, and we don't have to guess which bits you're showing us, and which bits yo're not. There's some really helpful advice on that here: stackoverflow.com/help/mcve And don't feel dumb - everyone starts somewhere! Good luck!
            – Tim
            Nov 10 at 14:17











          • Lastly, remember that if you like this answer and the other answer on this page, or in fact any answer on the site, you can click the "up" arrow to vote for them as "useful answers".
            – Tim
            Nov 10 at 14:21










          • it says I have a too low reputation so it doesnt display my vote :p i guess i need to be more active
            – Bruh
            Nov 11 at 11:50










          • @Bruh My mistake. You need fifteen reputation to vote up. There you go, now you have it. :-) stackoverflow.com/help/privileges
            – Tim
            Nov 11 at 12:04















          Hi thanks for your answer ! For the includes, I didn't put them here on purpose, in order to give you guys something a bit cleaner to look at. I didn't know I had to rewind the pointer, I guess that makes sense, you make me feel dumb lol, thank you so much ! Also, as for typedef : struct vect vect; I seem to have forgotten to copy/paste it from my code, my bad :D
          – Bruh
          Nov 10 at 13:52





          Hi thanks for your answer ! For the includes, I didn't put them here on purpose, in order to give you guys something a bit cleaner to look at. I didn't know I had to rewind the pointer, I guess that makes sense, you make me feel dumb lol, thank you so much ! Also, as for typedef : struct vect vect; I seem to have forgotten to copy/paste it from my code, my bad :D
          – Bruh
          Nov 10 at 13:52













          @Bruh Glad that helps! For next time you ask a question, please reduce your code to as little as possible which shows the problem, and then post all that code. This way bits which you don't know are important are included, and we don't have to guess which bits you're showing us, and which bits yo're not. There's some really helpful advice on that here: stackoverflow.com/help/mcve And don't feel dumb - everyone starts somewhere! Good luck!
          – Tim
          Nov 10 at 14:17





          @Bruh Glad that helps! For next time you ask a question, please reduce your code to as little as possible which shows the problem, and then post all that code. This way bits which you don't know are important are included, and we don't have to guess which bits you're showing us, and which bits yo're not. There's some really helpful advice on that here: stackoverflow.com/help/mcve And don't feel dumb - everyone starts somewhere! Good luck!
          – Tim
          Nov 10 at 14:17













          Lastly, remember that if you like this answer and the other answer on this page, or in fact any answer on the site, you can click the "up" arrow to vote for them as "useful answers".
          – Tim
          Nov 10 at 14:21




          Lastly, remember that if you like this answer and the other answer on this page, or in fact any answer on the site, you can click the "up" arrow to vote for them as "useful answers".
          – Tim
          Nov 10 at 14:21












          it says I have a too low reputation so it doesnt display my vote :p i guess i need to be more active
          – Bruh
          Nov 11 at 11:50




          it says I have a too low reputation so it doesnt display my vote :p i guess i need to be more active
          – Bruh
          Nov 11 at 11:50












          @Bruh My mistake. You need fifteen reputation to vote up. There you go, now you have it. :-) stackoverflow.com/help/privileges
          – Tim
          Nov 11 at 12:04




          @Bruh My mistake. You need fifteen reputation to vote up. There you go, now you have it. :-) stackoverflow.com/help/privileges
          – Tim
          Nov 11 at 12:04










          Bruh is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          Bruh is a new contributor. Be nice, and check out our Code of Conduct.












          Bruh is a new contributor. Be nice, and check out our Code of Conduct.











          Bruh is a new contributor. Be nice, and check out our Code of Conduct.













           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238846%2fc-accessing-a-structure-array%23new-answer', 'question_page');

          );

          Post as a guest














































































          這個網誌中的熱門文章

          Barbados

          How to read a connectionString WITH PROVIDER in .NET Core?

          Node.js Script on GitHub Pages or Amazon S3