Q: How to get specific data from text line I am trying to get the address of a certain line in a text file. This line contains the following; 
Kmart, 7055 East Broadway, Tucson AZ
I am using strcpy and strtok functions to extract the address (7055 East Broadway), but so far I've only been able to extract the name of the store (Kmart) using my code. 
char strLine[] gets the line from the file and I would like to return it to char strAddress[]
How would I extract just the address and possibly the city and state?
#define MAX_CHARS_PER_LINE 80

void getAddress(char strAddress[], const char strLine[])
{

   char newLine[MAX_CHARS_PER_LINE+1];

   strcpy(newLine,strLine);
   char* token = strtok(newLine, ",");

   strAddress = token;

   printf("%s\n",strAddress);


}


A: Assuming,


*

*The address is the second element in the line

*It is demarcated with commas.


You can use strtok to get the address as below.
void getAddress(char strAddress[], const char strLine[])
{
   char newLine[MAX_CHARS_PER_LINE+1];

   strcpy(newLine,strLine);

   char* token = strtok(newLine, ",");
   if (token != NULL)
   {
        token = strtok(NULL, ",");
   }
   if (token != NULL)
   {           
       strcpy (strAddress,token);
   }            
   return; 
}   

To get the city and state just call token = strtok(NULL, ","); one more time

What if I wanted to separate the city-state and just get the city and get the state separately? 

This is a more complex job as you do not have a comma in between the city and the state. You also need to take care of the case where the city can have two words e.g. New Orleans.
You can possibly assume that the state has 2 characters. In this case, a suggested route is


*

*Isolate City + State in a string

*Remove spaces at the end of the string

*The last 2 characters of the string are the state.

