title: C++ errors for C code
body: <p><strong>2nd EDIT</strong>: </p>
  
  <p>Thank you guys for the help so far!!! I have corrected everything in terms of plain c as that is what my assignment has to be written in. Obviously, my knowledge of C is terrible. I am literally teaching myself C as I write this, but using all of my c++ knowledge to do so. Hence my confusion of the language literals. I am still having issues with my firstCheck() function though. I will explain directly below with my current code.</p>
  
  <p>The firstCheck() function is not working like it should. In readFile() function I have successfully split the text from a given file into  an array line by line.
  Then firstCheck() should take that array "myString" and read the first string up until a " " occurs (basically the first word/character/etc.) so that I can evaluate it.</p>
  
  <p>Updated Assem.c</p>
  
  <pre><code>#include "assem.h"
  
  int readFile(FILE *file, struct assem *item) 
  {
  size_t i =0;
  item-&gt;counter = 0;                                                                      //this is sort of the constructor, if you will. 
  size_t maxLines = sizeof item-&gt;myLines / sizeof *item-&gt;myLines;
                                                                                          //breaks down text file into line by line 
  while(i &lt; maxLines &amp;&amp; fgets(item-&gt;myString, sizeof item-&gt;myString, file))               //and stores them into "myLines array"
      {
          item-&gt;myLines[i] = strdup(item-&gt;myString);
          i++;
          item-&gt;counter++;
      }   
  
  return 0;
  }
  
  void printFile(struct assem item)                                               //just printing things..prints it with a new line in front
  {
              printf("\n");
      for(int s = 0; s &lt; item.counter; s++)
          {
              printf("%s\n", item.myLines[s]);
          }
              printf("\n");
  }
  
  int firstCheck(struct assem item)               
  {
      char *myWord [7] = {NULL};
  
      for(int s = 0; s &lt; item.counter; s++)   
          {
          while(strcmp( fgets( item.myString, sizeof item.myString, stdin ), " " ) != 0 )         
              {
                  myWord[s] = strdup(item.myLines[s]);
              }           
          }
  
          for(int s = 0; s &lt; item.counter; s++)
          {
              printf("%s\n", myWord[s]);
          }
  
  return 0;       
  }
  </code></pre>
  
  <p>Updated "assem.h"</p>
  
  <pre><code>#include &lt;stdio.h&gt;
   #include &lt;stdlib.h&gt;
   #include &lt;string.h&gt;
  
  struct assem
          {
                  char myString[101];                     //buffer
                  char *myLines[20];                      //this will store the lines from a text file..up to 20 lines
                  int counter;                            //counter for number of lines
                                                          //printing stuff...prints file directly from whats STORED IN THE ARRAY
  
          };
  
          int readFile(FILE *FileToBeRead, struct assem *item);       //takes in the file that needs to be read and splits it into lines
          int firstCheck(struct assem item);
          void printFile(struct assem item);
  </code></pre>
  
  <p>Updated "main.c"</p>
  
  <pre><code>#include "Assem.c"
  
      int main()
      {
          struct assem test;
          FILE *mips;
          mips = fopen("/home/rpf0024/cse2610/Program1/mips.asm", "r");
          readFile(mips, &amp;test);
          printFile(test);
          firstCheck(test);
          fclose(mips);
          return 0;
      }
  </code></pre>
  
  <p><em>1st EDIT OLD</em>:
  I am currently writing some code that is getting errors but Im not sure how to fix them. Any explanation for these?
  The errors are within my firstCheck() function which attempts to read a string up until the first ' ' character in *myLines[] array. Basically, I am trying to read the first word up until a space occurs, store it in another array so that I can evaluate it.</p>
  
  <p>Here are the following errors:
  Errors are associated with firstCheck() function all the way at the bottom of my .c file..I have the line numbers commented.</p>
  
  <blockquote>
    <p>Assem.c:35:31: error: ISO C++ forbids comparison between pointer and
    integer [-fpermissive] Assem.c:37:31: error: cannot convert ‘char**’
    to ‘const char*’ for argument ‘1’ to ‘char* strdup(const char*)</p>
  </blockquote>
  
  <p>.c file</p>
  
  <pre><code>#include "assem.h"
  
  int assem::readFile(FILE *file) 
  {
  int i =0;
  counter = 0;                                            //this is sort of the constructor, if you will. 
                                                          //breaks down text file into line by line 
  while(fgets(myString, 101, file) != NULL)               //and stores them into "myLines array"
      {
          myLines[i] = strdup(myString);
          i++;
          counter++;
      }   
  
  return 0;
  }
  
  void assem::printFile()                 //just printing things..prints it with a new line in front
  {
              printf("\n");
      for(int s = 0; s &lt; counter; s++)
          {
              printf("%s\n", *(myLines+s));
          }
              printf("\n");
  }
  
  int assem::firstCheck()                 
  {
      char *myWord [7];
  
      for(int s = 0; s &lt; counter; s++)        //33
          {
          while(gets(*(myLines+s)) != ' ')    //35            
              {
                  myWord[s] = strdup(myLines); //37
              }           
          }
  return 0;       
  }
  </code></pre>
  
  <p>.h file</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  class assem
  {
  
      public:
          char myString[101];                     //buffer
          char *myLines[20];                      //this will store the lines from a text file..up to 20 lines
          int counter;                            //counter for number of lines
          int readFile(FILE *FileToBeRead);       //takes in the file that needs to be read and splits it into lines
          int firstCheck();
          void printFile();                       //printing stuff...prints file directly from whats STORED IN THE ARRAY
  
  };
  </code></pre>