I’m getting the wrong letters printed when I run a function like this:
#include <stdio.h>
void getletters(char *one, char *two) {
scanf("%c %c",&one, &two);
/* if i print one and two here, they are correct). */
}
int main(void) {
char one, two;
getinput(&one, &two);
char *pone = &one;
char *ptwo = &two;
printf("your letters are %c and %c", *pone, *ptwo); /* These are coming out as the wrong characters */
}
Do I have incorrect syntax? Am I using pointers incorrectly?
You accept pointers-to-char, then use the
&operator to get pointers-to-pointers-to-char, then provide them to a function expecting pointers-to-char.You also have a typo in it.
Instead, write: