Im sorry guys I was not clean and now I realize it.
I now see what you guys where talking about, and you are correct that
I was way off.
I have:
char *temp;
//Lets say that this is pointing to the word "Samples"
Ok. For example, you might have declared:
char *temp = "Samples";
or, better:
const char *temp = "Samples";
char *temp2
//Lets say that this is pointing to the number '32'
Um, let's say it isn't. What exactly do you mean when you say that
temp2 points to the number '32'?
Details of syntax are very important. "32", '32', and 32 are three
*very* different things; "32" is a string literal, '32' is a character
constant (whose meaning is implementation-defined; you almost
certainly don't want that), and 32 is an integer constant, of type
int.
temp2 cannot point to the *number* 32. (Well, there are ways that it
can, but I don't think that's what you're trying to do.) If you
wanted to point to a number, you'd need something of type int*, not
char*. (A char can hold a small number, but again, I don't think
that's what you're trying to do.)
As you can see, your description leaves open so many possiblities that
it's very hard to tell what you're really asking.
I'm going to *guess* that you mean that temp2 points to the string
"32", as in:
const char *temp2 = "32";
If that's correct, then temp2 points to a string; "32" is not a
number.
What do you mean by "null" here? All we can tell is that samples is a
variable of type int, and you haven't initialized it.
I need a statement that does this:
If (temp1 is equal to the word 'samples')
set samples to the value of temp2 (32).
Remember the distinction between single quotes and double quotes. I
think you mean "samples", not 'samples'.
What is temp1? You've declared temp and temp2; I see nothing called
temp1. I'm going to guess that you meant to say temp rather than
temp1, but the more you make us guess, the harder it is to help you.
So far I got (with your help)
if (strcmp(temp, "samples") == 0) //if temp == samples
{
//makes samples = temp2
}
And now we're back to temp again.
but im unsure of how to get the middle statement. Thanks again guys I
hope this is clearer. I reduced my code down to what i thought was
minimal but looking back it wasn't enough code to work off of
initially. Thanks!
Ok, if all my guess so far have been correct, then samples is a
variable of type int, and temp2 (which is of type char*) points to the
string "32". Given that, you want to assign the int value 32 to
samples. Is that correct?
If so, an assignment or a cast won't do the job. What you have is a
string, a sequence consisting of the characters '3', '2', '\0' (the
'\0' is a null character, the implicit string terminator). What you
want is the integer value 32. There's no operator built into the
language that will perform this translation for you -- but there are
routines in the standard library that will do the job. The simplest
one is atoi(), but I wouldn't advise using it except in a
quick-and-dirty program to be thrown away after you're done with it;
it does no real error checking.
The strtol function is the "right" way to do this. Using it is
moderately complex, but it does all the right error checking (for
example, if the input string doesn't look like a number, or if it does
but the value is too big, then strtol can tell you). The atoi
function is defined to work just like strtol except that any error
information is thrown away.
You might consider using atoi for a first draft of your program, just
to make sure you've got the logic right, then modifying it to use
strtol. Your system should include documentation for both functions.
Read it.
I realize it may seem that I'm being incredibly picky, but your
compiler is going to be just as picky, without being willing to guess
what you really meant.