Code:
#include <stdio.h>
int main()
{
char words[20];
This is to tell it how many characters are in the variable's value, right? Is "words" the variable, and if it is, how do I give it it's value?
Yes you are absolutely correct, words is the variable! There are several ways in which you can give a char variable a value, if you want to put more than 1 character (string or 'words') you could the same as with the letter varible earlier in this post (just change the ' ' quotes for " " ), or you could also use the scanf function that I mentioned to you before (remember, if you don't quite understand how that function works, just keep reading).
Actually, what I meant was how I give words it's value (it's single letter or mulitple words), as in, do I give "words" it's value by doing this:
Code:
#include <stdio.h>
int main()
{
char words [20] = "Hey, my name is Joe.";
Or by:
Code:
words = "Hey, my name is Joe.";
or some other way?
Also, if I can do this:
Code:
#include <stdio.h>
int main()
{
char words[] = "I am the best";
and let the computer figure out how many characters there are, why would I ever want to use the previous example and find the number of characters myself?
--------------------------------------------------------------------------------
That is a good question, I used to have the same questions when I was starting up. Anyway, the real potential of variables is that you can change there values anytime and as many times as you want, and char varibles are almost always used to store something the user types. For example, you want to make a program in which the program asks what is the name of the user, and then the user types his name. This name is stored in a char variable and later used in a printf statement to display "Hello NAME!!!". And this is why you normally don't put values to char variables, you just declare them. If you have any other questions, feel free to ask.
Either I'm misunderstanding your answer or you misunderstood my question, but it sounds like your telling me why people don't specify the number of characters in a value (char[]) sometimes. I was actually asking why I would I want to put:
Code:
#include <stdio.h>
int main()
{
char words [20];
and find out how many characters there are (20) rather than letting the computer do that:
Code:
#include <stdio.h>
int main()
{
char words[];