#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?
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,
sizeof(char)
is guaranteed to be 1 in C, no need to use it as multiplier