//// Blog.C/Trivia.FunctionInGets()
// KopyLeft: Code by KoffeeAddikt 09.Aug.03
// THIS CODE BELONGS TO THE PUBLIC DOMAIN
// USE AT YOUR OWN RISK!

#include<stdio.h>

char * string(int type){ // declares a variable and returns that variables' address
 char str[512];
 char temp;
 if(type == 0){
  return str;
 }
 if(type == -1){ // string(-1) prints the string
  printf("%s", str);
  return str;
 }
 else{ // returns the address of the type'th character
  temp = str[type - 1]; // 1st character, index = 0
  return &temp;
 }
}

main(){
 char seed = 'A';
 char * test;
 gets(string(0)); // string(0) returns address, gets operates on addresses
 printf("%s \n", string(0)); // printf (%s) also operates on addresses
 string(-1); putchar('\n'); // just printf()
 printf("%c\n", *string(1)); // printf first letter of input
 // string(1) = seed; // invalid assignment!
 printf("input again: ");
 test = gets(string(0)); // a new use for gets
// test = gets(); // error! remove comment tag to try
 puts(test);
// string(0) = "you're mad!"; // invalid assignment, remove comment tag to try
 getch();
}

/*

PROGRAM NOTES
1. If you have a function that has a declaration, why does calling that function
     different times give you the same address? Won't the function create a new
     variable each time it is called? Does the program do it? Or is it only in
     Windows? Honestly, I don't know, so please answer me.
2. DevC++ compiler says for return str; : "[Warning] function returns address of
     local variable" I don't think that's bad.
3. gets() operates on addresses!
4. I think you could use functions like string() to eliminate global variables.
     I still have to check with my teacher about Program Note #1

*/