I am studying C my self and trying to do some exercise.
The exercise requires 2 functions, one to takes three parameters (one string holds questions, one string holds user 's answers, and one integer limits the characters of the answer. The other function is the main function that uses the previous function to ask the user and prints the full name.
I also tried to write the code but there is a problem which I can not find it out by myself. Can any one show me the mistake and explain it for me ?
Thanks all.
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define SIZE 100
void func(char, char, int);
int main(void)
{
char str1[] = "Enter your first name: ";
char str2[] = "Enter your middle name: ";
char str3[] = "Enter your last name: ";
char answer[SIZE];
func(str1, answer, SIZE);
func(str2, answer, SIZE);
func(str3, answer, SIZE);
printf("Your full name is: %s", answer);
}
void func(char *a, char *b, int max_size)
{
char temp[100];
int i;
printf("%s", a);
gets(temp);
i = strlen(temp);
if(i < max_size)
{
strcat(b, temp);
}
else
{
printf("You enter too much characters.");
}
}