I'm learning C at the moment and I run into some problem, hard to understand what is going on with variables and adding text to variable in C.
I know C is not treating the strings and character as in other programming language. If I understand it correctly from my book: I have to define a variable before I can use it, that's ok for me. So, If I do this code, where I wish to print the variable text_1 it is failing:
#include <stdio.h>
int main()
{
char text_1[];
text_1[] = "Testing";
printf("Test 1 is: %s", text_1);
return(0);
}
But if I do this way, this is working:
#include <stdio.h>
int main()
{
char text_1[] = "Testing";
printf("Test 1 is: %s", text_1);
return(0);
}
In some other programming language I can do this way: Dim a as string
a="Testing"
print("Testing 1 is:", a) --> or similar option to print out the variable 'a'.
What is the correct way to do this in C?
Thank you.