So the point of this code, was to take a number and then that number will mean you are allowed to concatenate a number of string so to the original string.
It worked!!
But, not as well as I'd hoped.
There is a TEENY tiny bug in this code, for example if i type the number five and for my strings I type the strings "The Friends of Ringo Ishikawa"
I get TheFriendsOfRingoIshikawa as intended, but before that comes these this weird character and an a. So, if I type in the number 5 when prompted and then The Friends of Ringo Ishikawa I get the output: ö aTheFriendsOfRingoIshikawaIshikawa
What happened?
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdarg.h>
char*variable_string(int num, char*a, ...);
int main()
{
int num = 0;
char*string = (char*)malloc(sizeof(char)*100);
string[100] = '\0';
printf("Please enter the number of strings you want to add to the string.");
scanf("%d", &num);
printf("\n num is %d", num);
printf("\nNow please enter the strings you wish to involve in your char");
for(int i = num; i > 0; i--)
{
printf("\nnum is %d", i);
//fgets(string, sizeof((char*)string), stdin);
scanf("%s", string);
/*printf("\n%s", string);*/
variable_string(num, string);
}
//variable_string(num, string);
printf("\nand the string is %s", variable_string(num, string));
return 0;
}
char*variable_string(int num, char*x,...)
{
va_list arg_ptr;
char*a = (char*)x;
va_start(arg_ptr, x);
char*b = va_arg(arg_ptr,char*);
strcat((char*)b, (char*)a);
va_end(arg_ptr);
//printf("%s", (char*)b);
return (char*)b;
}