N
Nick Keighley
Thank you! That's a point to start.
so why are you still here?
seriously the answer to the question "how do i do string handling" is
radically different depending on whether you're using C++ or C. C++'s
string handling is far more sophisticated. With C you should probably
acquire (or write!) a decent string handling library. And if you've
got serious serious string handling problems consider a more string
oriented language.
C has no "methods"
or functions to get substrings from a string,
or to take "spaces" ("blanks") away (a typical ["trim"] function)??
no not really
What I exactly need to do is the following:
get hold of a decent tutorial
eg. http://en.wikipedia.org/wiki/The_C_Programming_Language_(book)
and an online reference
eg. http://www.dinkumware.com/manuals/
While there are still new lines:
(1) Get one line from a given text file.
fgets()
(2) In that line, detect a "first" part and a "second part", which are
separated by a "=" symbol.
(3) Take away the possible "blanks" (like a "trim" function would do)
from those parts.
(4) Detect which variable in my program is being referred by the
"first part".
(5) Translate the second part (it is still a "string") into a number.
sscanf() can do most of this (not step 4 though!)
int first;
char second [MAX_SIZE_SECOND];
if (sscanf (line, "%s = %d", &first, second) != 2)
{
/* report error */
}
else
{
/* process stuff */
}
- About #1 : It can be done by means of standard I/O C libraries. I
guess that there are also ways to do it with C++ libraries.
for C++ answers ask in comp.lang.c++ !
- About #2 : [...]
there IS a C standard function
for getting the position of a character (it is "strchr"), but not a
function for substring (unless it is a substring that starts at
position 1, which can be done with "strncpy_s").
don't use strncpy() use strcpy() (or sscanf()!)
[...]
- About #4 : I can do this by using a "case" or an "if" statement.
yes.
No
problem at all with this step, provided that "first part" has been
successfully extracted and trimmed.
- About #5 : I hope that a proper casting statement will be enough.
no casting won't help you. Use sscanf() or strtod() (or one of its
friends)
<snip>