TechArena Community Random Function to Concatenate 2 strings

#1
14-10-2009
 Member Join Date: Aug 2009 Posts: 36
Random Function to Concatenate 2 strings

I have a problem for the creation of my program, here's what I'd like to do:

cVar1 char = 0;
cVar2 char = 0;
cVar3 char = 0;
cVar4 char = 0;

The name comes from a scanf which wants and now it does this:

cVar1 char = a;
char cVar2 = b;
cVar3 char = c;
char cVar4 = d;

how can they repeated on both lines at random?
#2
14-10-2009
 Member Join Date: May 2008 Posts: 2,293
Re: Random Function to Concatenate 2 strings

What you want to do: the user enters two strings, and you mix all the characters and redistributed at random from the 2 channels, right? If so, I advise you to consider the function ran () "and the modulo operator (%). Basically ran function generates a random number and the% operator can transform into a number small enough to serve as an index of your chain.
#3
14-10-2009
 Member Join Date: Jan 2009 Posts: 199
Re: Random Function to Concatenate 2 strings

To concatenate a string, remember that strings are basically arrays of characters.If you have string1 = "dot1" and string2 = "dot2". To concatenate 2 strings you can use simbol +. So, string1 + string2 will be one string.
#4
14-10-2009
 Member Join Date: Dec 2008 Posts: 177
Re: Random Function to Concatenate 2 strings

The cVar1 = a, and% s is not set, It should be an array (cVar1 [100] for example). Then you must use the ran and the module. Personally I'd make a 2D array. You put your sentences in cvar [0], cvar [1], cvar [2], cvar [3] and you display them like that cvar [rand ()% 4].

 Tags: