Strange compiler complaint when using similar code

Posted by Jason on Stack Overflow See other posts from Stack Overflow or by Jason
Published on 2011-03-20T16:03:32Z Indexed on 2011/03/20 16:10 UTC
Read the original article Hit count: 189

Filed under:
|
|

For a project, I have to ask the user for a file name, and I'm reading it in character by character using getchar.

From the main, I call the function char *coursename= introPrint(); //start off to print the usage directions and get the first bit of input. That function is defined as

char *introPrint(){
  int size= 20;
  int c;
  int length=0;
  char buffer[size];


  //instructions printout, cut for brevity

  //get coursename from user and return it
  while ( (c=getchar()) != EOF && (c != '\n') ){
    buffer[length++]= c;
    if (length==size-1)
      break;

  }
  buffer[length]=0;
  return buffer;
}

This is basically identical code I wrote to ask the user for input, replace the character echo with asterisks, then print out the results. Here, though, I'm getting a function returns address of local variable warning for the return statement. So why am I getting no warnings from the other program, but trigger one for this code?

© Stack Overflow or respective owner

Related posts about c

    Related posts about compiler-errors