0

While trying to answer this question, I discovered the following strange issue with sscanf.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int main(void){
    const char* lit ="George Washington, 2345678";
    char buffer[1024];
    int out = 0;
    memset(buffer, 0, 1024);
    sscanf(lit, "%50[^,]s, %d\n", buffer, &out);
    printf("%s %d\n", buffer, out);
}

The output of this code is George Washington 0.

Why is this and how can it be corrected?

I have already looked at this and this.

Community
  • 1
  • 1
merlin2011
  • 71,677
  • 44
  • 195
  • 329

0 Answers0