I have read all the text from a desired file and it is now stored in buff
. I want to copy just the string content after identifier strings such as 'Title'.
Example file below:
"Title: I$_D$-V$_{DS}$ Characteristic Curves (Device 1)
MDate: 2016-03-01
XLabel: Drain voltage V$_{DS}$
YLabel: Drain current I$_D$
CLabel: V$_{GS}$
XUnit: V
... "
for(;;) {
size_t n = fread(buff, 1 , DATAHOLD, inFile);
subString = strstr( buff, "Title");
if( subString != NULL) {
strcpy(graph1.title , (subString + 7));
subString = NULL;
}
....more if statements....
if( n < DATAHOLD) {
break;
}
}
I understand that strstr()
returns a pointer to location of the search string, I added 7
to get just the text that comes after the search string and this part works fine. The problem is strcpy()
copies the rest of buff
character array into graph1.title
.
How to instruct strcpy()
to only copy the text on the same line as the substring
pointer? Using strtok()
maybe?