iam trying to use only one function to get the value of add and sub. if there is a label i want to ignore it. 

file.txt
------------------------
label: add $1,$2,$2
       sub $1,$2,$2
-----------------------




int main()
{

   char line2[20];        
   char tem_line2[20];

   char *tptr;

   while(fget...line2)   //read one line and store in char line2[20];
   {
     strcpy(tem_line2, line2);  //store same value in different array
     if(strstr(line2,":") == 0)  //if there is a label, ignore 1st word
     {
        tptr = strtok(line2, " \t\n");
        if(tptr != NULL)
        {
            funct1(line2);
        }
     } 
     else                       //if there is no label than dont ignore 1st word
     {
       funt1(line2);
     }
    }
}


funct1(char line2[])
{
  char *tem_tptr;

  tem_tptr = strtok(line2, " \t\n");    //here i should have value add, or sub
  if(tem_tptr != NULL)
  {

  }
}

Try something like:

#include <string.h>
#include <stdio.h>

void funct1(char line2[]) {
  char *tem_tptr;
  tem_tptr = strtok(line2, " \t\n");    //here i should have value add, or sub
  if(tem_tptr != NULL) {
     printf("\tInside funct1: %s\n",tem_tptr);
  }
}

int main()
{
   char line2[20];        
   char tem_line2[20];
   char *tptr;

   while(fgets(line2,20,stdin))   //read one line and store in char line2[20];
   {
     strcpy(tem_line2, line2);  //store same value in different array
     if(tptr=strstr(line2,":"))  //if there is a label, ignore 1st word
     { 
        // If we are not at the end of the input string, process it
        // First +1 is for number of bytes, the second is because
        // I want to move to the byte after where the ':' was found
        // Have to check if the string is long enough
        if ( (tptr-line2+1+1) < strlen(line2)){
           tptr++ ;
           funct1(tptr);
        } 
        else {
           printf("Bad data\n");
        }
     } 
     else                       //if there is no label than dont ignore 1st word
     {
       funct1(line2);
     }
    }
}
Output:
$ ./a.out
label: add $1,$2,$2
    Inside funct1: add
sub $1,$2,$2
    Inside funct1: sub
label:
Bad data
^C
$
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.