And what does this main do for you?
Code:
int main(){
char* input;
char* input2;
input = readLine("Please enter a number: ", 256, 1);
input2 = readLine("Please enter a number: ", 256, 1);
printf( "You entered %s.\n", input);
printf( "You entered %s.\n", input2);
return 0;
}
Edit: Of course it doesn't have to be a call to the same function to reuse the memory; try this:
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char* readLine(char* message, int maxSize, short pad){
char string[maxSize];
int i;
printf(message);
fgets(string, maxSize, stdin);
for (i = 0; i < maxSize; i++ ){
if ( string[i] == '\n' ){
string[i] = '\0';
if(pad){
return string;
}else{
char temp[i + 1];
strcpy(temp, string);
return temp;
}
}
}
return string;
}
int silly(void) {
int bob[64] = {0x41424344, 0x45464748, 0x49000000};
return bob[2];
}
int main(){
char* input;
int foo;
input = readLine("Please enter a number: ", 256, 1);
foo = silly();
printf( "You entered %s.\n", input);
printf( "I entered %d.\n", foo);
return 0;
}