I am trying to use pointers to save characters to an array but when I run the program, it saves all but the last character and instead replaces it with something random.
Here is the code:
#include <stdio.h>
void inputCharArray(char *beg, char *end){
char *current = beg;
while (current != end) {
scanf("%c ", current);
current++;
}
}
int main(void) {
int size, position;
position = 0;
printf("Size of array: ");
scanf("%d", &size);
char letters[size];
printf("Array: ");
inputCharArray(&letters[0], &letters[size]);
printf("%s", letters);
return 0;
}
And here is what I get when I run the program:
Size of array: 3
Array: a s d
as▒
Any help or direction would be appreciated.