Hacker News new | ask | show | jobs
by plikan13 4154 days ago

  int get_number(char buffer[])
  {
    long int i = 0;
    char *p;
    if(fgets(buffer, sizeof(buffer), stdin) != NULL)
  {
sizeof(buffer) will always be 4 (or 8 if you compile 64 bit) because sizeof(pointer to char) is 4 (or 8). It will NOT be the size of the buffer that you pass as an argument. To fix this problem you need to change the function to

  int get_number(char buffer[], int buffer_size)
Also the buffers that you pass to this function seem to be too small.
1 comments

thank you very much. i appreciate it!