0

Im pretty new to C. And i was stumbeling on %m in scanf when i was trying to build a function similar to input() in Python3.

And i tried it and it worked i i dont know why. The code:

void *input(char *startStr){
      char *str;
      printf(startStr);
      scanf("%m[^\n]", &str);
return str; }

The %m doesn't seem to be a standard specifier in C. My dev environment is on Ubuntu with gcc 6.2.0?

Any Captain here that could explain it for me?

And thank you for being Awesome people on this community!

EDIT: We can close this question, all the links provided will explain it, and there's a similar question asked, that didn't show up when i searched StackOverflow for my problem. But now i'm enlightened in this question, and i hope all others in their hunt for enlightenment will follow the links provided to get their answer in this particular domain of specifiers for scanf.

difference between %ms and %s scanf

https://linux.die.net/man/3/scanf

https://linux.die.net/man/3/sscanf

thartvik
  • 19
  • 3
  • 1
    Refer http://stackoverflow.com/questions/20577557/whats-the-meaning-of-the-m-formatting-specifier – Sundararaj Govindasamy Apr 05 '17 at 17:37
  • The other thread is how to use it in a printf, for error handeling, i read it and the links it still doesent explain the usage in a scanf and how it works in a scanf. – thartvik Apr 05 '17 at 17:45
  • See [this part of m modifier and example](https://linux.die.net/man/3/scanf) – BLUEPIXY Apr 05 '17 at 17:48
  • 2
    [This page](https://linux.die.net/man/3/sscanf) says *"... An optional 'm' character. This is used with string conversions (%s, %c, %[), and relieves the caller of the need to allocate a corresponding buffer to hold the input: instead, scanf() allocates a buffer of sufficient size, and assigns the address of this buffer to the corresponding pointer argument, which should be a pointer to a char * variable (this variable does not need to be initialized before the call). The caller should subsequently free(3) this buffer when it is no longer required."* – Weather Vane Apr 05 '17 at 17:48
  • @WeatherVane _It is specified in the POSIX.1-2008 standard._ – BLUEPIXY Apr 05 '17 at 17:53
  • @Weather Vane Thank you for the links, they didnt show up when i googled. They explained it very well. – thartvik Apr 05 '17 at 18:11
  • @BLUEPIXY Thank you for the links, they didnt show up when i googled. They explained it very well. – thartvik Apr 05 '17 at 18:11
  • Not from knowledge but by googling "C scanf gnu format specifier %m" suggested by the first comment. – Weather Vane Apr 05 '17 at 18:24

0 Answers0