1

I wanted to pass the value of argv to a function but it is showing error so can any body hellp me my function

void init(void)
{
    // TODO
    int size = *dim;
    int row;
    int column;
    int element = size * size - 1;
    for (row = 0; row < size; row++ )
    {
        for(column  = 0; column < size; column++)
        {
            printf("%d", element);
            element++;
        }
        printf("\n");
    }
}

And in main it is something like this

int *dim;
    dim = atoi(argv[1]);
  • 1
    There's a button in the text editor showing {}. When posting code, select this code, and press the button. If any of the selected lines does not have 4 spaces in front, it'll add four spaces to each line, which in Stackexchange markdown is interpreted as code block. Clicking it while all lines have at least four leading spaces, it will remove four of them. – Blauelf Mar 24 '17 at 13:31
0

If dim is declared in main, you won't see it in init.
Your indentation lets me assume it's global instead. Please post in a way we don't have to guess!

You declare dim to be a pointer to integer, rather than a regular integer. Why?

You then don't assign a memory address to this pointer, but a number. It looks reasonable to me to store the number, just not in a pointer. I hope you ensured argc being 2 first?

Why not make dim an int instead of int*? You'd declare it globally, so any function defined in the same file can access it.

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .