How to pass an array as a parameter to another function?

I have this function that reads one line from a text file.   The file is a list of tokens from a previous scanner program.  I need to classified the tokens into their catergories.  I can't figure out how to use the result from this function and pass it to the other function that compares the tokens and classifies them into their category.  Can anyone help me out.

char getToken()
{
   int SIZE = 40;
   char line[ SIZE ];
 
   if(( tokfile = fopen( "tokens.txt", "r" )) != NULL )
   {
      if( fgets( line, 40, tokfile ) == NULL )
         printf( "fgets error\n" );
      else
         printf( "%s", line );
   }
   
   return line[ SIZE ];

}
morales7_0Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
You unfortunately cannot do it that way. The idea would be to

char* getToken()
{
  int SIZE = 40;
  char* line= new char[ SIZE ];

   if(( tokfile = fopen( "tokens.txt", "r" )) != NULL )
  {
     if( fgets( line, 40, tokfile ) == NULL )
        printf( "fgets error\n" );
     else
        printf( "%s", line );
  }
   
  return line;

}

And, of course, you need to 'delete[]' the returned value when you no longer need it. Another approach would be to

void getToken(char* line )
{
  int SIZE = 40;
  char line[ SIZE ];

   if(( tokfile = fopen( "tokens.txt", "r" )) != NULL )
  {
     if( fgets( line, 40, tokfile ) == NULL )
        printf( "fgets error\n" );
     else
        printf( "%s", line );
  }
   
  return line[ SIZE ];

}

and use it like

  int SIZE = 40;
  char line[ SIZE ];

  getToken(line);
 
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
morales7_0Author Commented:
Cool!!!  How would I compare the result from getToken() function with the list of categories in my tokenTable() function?    
0
jkrCommented:
>>with the list of categories in my tokenTable() function?

Sorry, but since I do not know that function, it is hard to give any advice on that :o)
0
SirHandoCommented:
You need to pass the address...

char getToken()
{
   int SIZE = 40;
   char line[ SIZE ];
 
   if(( tokfile = fopen( "tokens.txt", "r" )) != NULL )
   {
      if( fgets( &line, 40, tokfile ) == NULL )
         printf( "fgets error\n" );
      else
         printf( "%s", line );
   }
   
   return line[ SIZE ];
}

I do not know the point of returning line[SIZE] here either?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.