0xC000000005 that I don't understand

Hello guys, I have a double pointer char **input that has its double pointer part mem allocated but its input[i] part not mem allocated yet. Because its input[i] part not mem allocated, shouldn't these two codes elicit 0xC000000005 error in the main function? I am only starting to get my error when I start including input[2]. Can someone explain this to me?

1
2
    printf("%f\n", *input[0]);
    printf("%f\n", *input[1]);



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//other irrelevant codes unincluded
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{

    char a[100] = "( ( 3 + 4 ) * 5 ) - 5 * 7 * 5 - 5 * 10";
    int size = 1;
    for (int i = 0; i < strlen(a); i++){
        if(a[i] == ' ') size++;
    }
    char *ptr = strtok(a, " ");
    char **input = (char**)malloc(sizeof(char*) * size);

//    for (int i = 0; i < size; i++) {
//        input[i] = (char*)malloc(sizeof(char)* 2);
//    }

    printf("%f\n", *input[0]);
    printf("%f\n", *input[1]);
//    printf("%f\n", *input[2]);

    strcpy(input[0], ptr);
    printf("%c\n", *input[0]);
    ptr = strtok(NULL, " ");

    strcpy(input[1], ptr);
    printf("%c\n", input[1]);

    system("pause");

    return 0;
}
malloc doesn't initialize the memory returned, so there's no telling what's in input[0] and input[1] at lines 21 and 22. In addition, you're telling printf to print a floating point value but you're passing in a single character. So there's no telling what it will print.
> printf("%f\n", *input[0]);
Well,
1. %f isn't how you print a char (of any variety).

2. input[0][0] is a char (suitable for %c).
input[0] is a char pointer (suitable for %s, if you have a \0 in there somewhere).
Topic archived. No new replies allowed.