Help a newbie out with this program:
input--two strings from the user
output--one string with memory allocated.
for example: first and last name.
Here is my code--I'm obviously confused.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char add_strings (char *, char *);
char *newstring
main()
{
/*get two strings*/
char a[], b[];
printf ("\nEnter two strings of characters separated by a space: ");
scanf ("%s%s", a[], b[]);
/* allocate memory for the new array */
newstring = malloc (sizeof (newstring) * sizeof(char));
printf ("\nThe new string is %s.", add_strings (a, b));
return 0;
}
/* function add_strings(): concatenates two strings */
char add_strings (char *first, char *second)
{
char newstring = first;
/* some loop to add each element?? */
for
return ();
}
input--two strings from the user
output--one string with memory allocated.
for example: first and last name.
Here is my code--I'm obviously confused.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char add_strings (char *, char *);
char *newstring
main()
{
/*get two strings*/
char a[], b[];
printf ("\nEnter two strings of characters separated by a space: ");
scanf ("%s%s", a[], b[]);
/* allocate memory for the new array */
newstring = malloc (sizeof (newstring) * sizeof(char));
printf ("\nThe new string is %s.", add_strings (a, b));
return 0;
}
/* function add_strings(): concatenates two strings */
char add_strings (char *first, char *second)
{
char newstring = first;
/* some loop to add each element?? */
for
return ();
}