So I have a simple code that scans every letter of a word and writes it's value and adress using a pointer.
My problem is that %c doesn't scan spaces, and I would like them to. How do I manage that?
#include <stdio.h>
int main()
{
char c1, c2, *p_c;
while (scanf_s(" %c", &c1) == 1)
{
if (c1 == '*')
break;
p_c = &c1;
c2 = *p_c;
printf("c1: %c (%p) c2: %c (%p) c_p: %c (%p)\n", c1, &c1, c2, &c2, *p_c, p_c);
}
return 0;
}
For example
Input:
is this C?*
Expected output:
c1: i (00D3F7CF) c2: i (00D3F7C3) c_p: i (00D3F7CF)
c1: s (00D3F7CF) c2: s (00D3F7C3) c_p: s (00D3F7CF)
c1: (00D3F7CF) c2: (00D3F7C3) c_p: (00D3F7CF)
c1: t (00D3F7CF) c2: t (00D3F7C3) c_p: t (00D3F7CF)
c1: h (00D3F7CF) c2: h (00D3F7C3) c_p: h (00D3F7CF)
c1: i (00D3F7CF) c2: i (00D3F7C3) c_p: i (00D3F7CF)
c1: s (00D3F7CF) c2: s (00D3F7C3) c_p: s (00D3F7CF)
c1: (00D3F7CF) c2: (00D3F7C3) c_p: (00D3F7CF)
c1: C (00D3F7CF) c2: C (00D3F7C3) c_p: C (00D3F7CF)
c1: ? (00D3F7CF) c2: ? (00D3F7C3) c_p: ? (00D3F7CF)
My code just entirely skips spaces as if they weren't there at all. Thanks in advance.