# Thread: to assign a double and output it

1. ## to assign a double and output it

hi, so at the moment i have this code

Code:
```    char cint2[10] = "xyz";
char cint3[10] = "lol";

char my_string[] = {""};
char my_string2[] = {""};

printf("\n%s", cint2);

strcpy (cint2,my_string);
strcpy (cint3,my_string2);

double double1[2][2] = {{my_string,my_string2,my_string},{my_string2,my_string,my_string2}};

printf("\n%f", double1[2][2]);```
it outputs: 0.000000
anyone know the correct syntax?

2. Describe in detail in English what you are trying to accomplish. NO Source code!

Your code presented does not make any sense!

3. Originally Posted by rstanley
Describe in detail in English what you are trying to accomplish. NO Source code!

Your code presented does not make any sense!
ok,

so, in my current exercise, i am starting off with a char,

then, converting the char into an array,
then converting the array into a double,
then outputting the double

4. Originally Posted by WaterSerpentM
ok,

so, in my current exercise, i am starting off with a char,

then, converting the char into an array,
then converting the array into a double,
then outputting the double
One character, or several characters together?

'3' or "3.14"?

Was this exercise from a book or from a tutorial, or from somewhere else?

What is the full text of the "exercise"?

5. Originally Posted by rstanley
One character, or several characters together?

'3' or "3.14"?

Was this exercise from a book or from a tutorial, or from somewhere else?

What is the full text of the "exercise"?
the characters are "xyz" and "lol"

its my own exercise practicing calculations, variable conversions and outputs

6. Originally Posted by WaterSerpentM
the characters are "xyz" and "lol"

its my own exercise practicing calculations and outputs
Neither if these strings would ever convert to a double! You need to learn more aut C data types, and a whole lot more first!

7. Originally Posted by rstanley
Neither if these strings would ever convert to a double! You need to learn more aut C data types, and a whole lot more first!
so, only INT can be a double?

8. Originally Posted by WaterSerpentM
so, only INT can be a double?
Ints and doubles are two different things!

123 is an int.
123.45 is a float or a double depending on the data type of the variable.

"ABC" is a string of three chars, not an int or a double, and never will be!

Again, you need to study the language!!!

9. An int can be converted to a float or a double and vice versa, with some data loss.

There are many more data types than ints and doubles!

Char, int, short, long, long long, unsigned versions of all int types, etc....

Study the language!!!

10. Originally Posted by rstanley
Ints and doubles are two different things!

123 is an int.
123.45 is a float or a double depending on the data type of the variable.

"ABC" is a string of three chars, not an int or a double, and never will be!

Again, you need to study the language!!!
ye I kind of got muddled up a bit, I mistook double for an array,

so, all I want to do is,

create an array with a sequence of chars, then outputting the array,

is this possible?

11. Yes, but away from my computer. Will respond in a couple of hours.

12. Look at the following code and the output:
Code:
```#include <stdio.h>  // For printf() and scanf() functions
#include <stdlib.h> // For atoi() function

int main(void)
{
char ary[64] = "123"; // Initialize all local variables
int val = 0;
double dval = 0.0;

printf("The initial string in the array: %s\n\n", ary);

val = atoi(ary);
printf("The converted string to an int: %d\n\n", val);

scanf("%lf", &dval);  // The '&' is needed here.  scanf() needs an address
printf("The double value entered is: %lf\n\n", dval);

scanf("%s", ary);  // But not here.  ary is an address
printf("The name entered was: %s\n", ary);

return 0;
}```
Output:
Code:
```The initial string in the array: 123

The converted string to an int: 123

The double value entered is: 3.140000

The name entered was: John```
Is this what you are trying to do?

Normally, I would use fgets() to enter strings, but start with scanf().

I can't teach you the entire language here. You need to get a book and STUDY the language yourself!!!

13. Originally Posted by rstanley
Look at the following code and the output:
Code:
```#include <stdio.h>  // For printf() and scanf() functions
#include <stdlib.h> // For atoi() function

int main(void)
{
char ary[64] = "123"; // Initialize all local variables
int val = 0;
double dval = 0.0;

printf("The initial string in the array: %s\n\n", ary);

val = atoi(ary);
printf("The converted string to an int: %d\n\n", val);

scanf("%lf", &dval);  // The '&' is needed here.  scanf() needs an address
printf("The double value entered is: %lf\n\n", dval);

scanf("%s", ary);  // But not here.  ary is an address
printf("The name entered was: %s\n", ary);

return 0;
}```
Output:
Code:
```The initial string in the array: 123

The converted string to an int: 123

The double value entered is: 3.140000

The name entered was: John```
Is this what you are trying to do?

Normally, I would use fgets() to enter strings, but start with scanf().

I can't teach you the entire language here. You need to get a book and STUDY the language yourself!!!
that is not what I am trying to do

as I said before

I kind of got muddled up a bit, I mistook double for an array,
I am simply trying to output an array which is a set of chars

Code:
```    char dint1 = "poi";
char dint2 = "ghj";
char dint3 = "ggg";

char array123[3] = {dint1,dint2,dint3};

printf("\n%s"), array123[0];```
This not correct, but can kind of show what I am trying to do

14. I would also recommend studying the language from a good book. Asking question after question is a really slow way to learn it (it's a good way to become a Help Vampire though). After all, your questions (and questions you don't know to ask) have already been answered by any good C programming book.