I'm not familiar with the I/O protocol you are using, but since you have the iostream header file included in your program you could also add the fstream header file, declare an fstream in input mode or use an ifstream (which is an fstream in dedicated only to input), and then use the >> operator to separate A1 from A2 while reading from the file. Alternatively, if you must read char by char you could check each char as it is read from stream and if it is alphanumeric add it to a string and if it isn't then terminate current string, store it where however you want and read char from file until you find the next alphanumeric char to start the next string (using the isalphanum() function would make this easier for you if you try this type of protocol).