I am trying to figure out what the problem is with the code I wrote for returning a char array from a function. It prints out ascii characters instead of the word that was typed in. Would someone look at my code and tell me what I need to change to make it work? This is for a class at school and I must use printf and gets(). I've been several hours on this and just at my wits end with it.
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
using namespace std;
//prototype
char *get_c_String();
int main()
{
char *p;
p = get_c_String();
printf("\n\tThe name is %s\n\n", p);
system("pause");
return 0;
}// End of main
char *get_c_String()
{
char word[2][20];
printf("Enter a word: ");
gets(word[0]);
return word[0];
}
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
using namespace std;
//prototype
char *get_c_String();
int main()
{
char *p;
p = get_c_String();
printf("\n\tThe name is %s\n\n", p);
system("pause");
return 0;
}// End of main
char *get_c_String()
{
char word[2][20];
printf("Enter a word: ");
gets(word[0]);
return word[0];
}