I'm having trouble getting the parameters correct in my cat function. I would think since I'm changing temp that I would need to pass the address since I want to be able to see that in main. I think I'm getting screwed up by the decaying.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
/* Swaps strings by swapping data*/
void swap2(char *str1, char *str2)
{
char *temp = (char *)malloc((strlen(str1) + 1) * sizeof(char));
strcpy(temp, str1);
strcpy(str1, str2);
strcpy(str2, temp);
free(temp);
}
void cat(char *temp, char *strings_line_tokens[])
{
strcat (temp,strings_line_tokens[1]);
strcat (temp,strings_line_tokens[2]);
strcat (temp,strings_line_tokens[3]);
}
int main()
{
char str1[10] = "geeks";
char str2[10] = "forgeeks";
char temp[80] = {0};
char *strings_line_tokens[503] = {0};
int lower_bound_of_big_boy_counter = 0;
strings_line_tokens[0] = malloc(strlen("string")+1);
strcpy(strings_line_tokens[0], "string");
strings_line_tokens[1] = malloc(strlen("string1")+1);
strcpy(strings_line_tokens[1], "string1");
strcpy (temp,strings_line_tokens[0]);
lower_bound_of_big_boy_counter++;
cat(&temp, strings_line_tokens)
printf("temp is %s", temp);
swap2(str1, str2);
printf("str1 is %s, str2 is %s", str1, str2);
getchar();
return 0;
}