-2
#include <stdio.h>

#include <stdlib.h>

static void get_string(char *ac)
{
    ac = (char *)malloc (1 * sizeof (char));
    printf("Enter the string to count vowels and consonants in a string using pointers: ");
    scanf("%s", ac);
}

main(int argc, char *argv[])
{
    char *ac = NULL;
    get_string(ac);
    printf("The Entered string is:%s", ac);
    for(;;);
}

Could not get the entered string from the stack of function. Returns null.Can anyone help me in debug?

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
jiju
  • 11
  • 2
  • 8

1 Answers1

1

Function arguments in C is passed by value. Any changes made to the parameters from inside the called function will not reflect to the actual argument supplied at function call.

In your case, you wanted to change ac itself (not the content of the memory location it points to), so, that would need a pointer-to-ac.

That said,

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261