0

I am having an issue reading in a file with a certain format using strtok. Each line in the file contains a format as shown below:

Bill Simpson, 01452356

When I display only temp_id I get (Underscore = whitespace):

"_01452356" 

The code for breaking apart each line is as follows:

while((fgets(temp_string, LENGTH, ifp))!= NULL)
    {
          temp_name = strtok(temp_string, comma);
          temp_id = strtok(NULL, comma);
          add(temp_name, temp_id);
    }

I simply want temp_id to not contain whitespace. Keep in mind that temp_name and temp_id are both arrays of type char. I would greatly appreciate a quick solution to this issue.

Mehdi Maghrouni
  • 1,529
  • 22
  • 23
  • possible duplicate of [How do I trim leading/trailing whitespace in a standard way?](http://stackoverflow.com/questions/122616/how-do-i-trim-leading-trailing-whitespace-in-a-standard-way) – Mouser Jan 31 '15 at 19:05

1 Answers1

0

You need to explicity include the space character as a delimiter.

char comma[] = ", ";

They could be the other way round

char comma[] = " ,";

because they are not a sequence, but a set of chars that may be delimiters.

Weather Vane
  • 33,872
  • 7
  • 36
  • 56