So I'm creating a program that produces a random string, then allows the user to enter a string, followed by a symbol. The random string is then compared to the entered string and the symbol string replaces when the chars are equal. This is a skeleton so far (Trying to get the basic components working before I do error checks) and I'm simply not doing the swap correctly. I thought that going by individual memory indices and comparing those then placing the string when equal would be the way but after taking the symbol the program just exits out. This is also done with just array notation Any suggestions would be greatly appreciated.
Code:
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
char *rando(char rarray[]);
void *generated(char string1[]);
char *symbol(char symb[], char rarray[], char string1[], char Farray[]);
int main()
{
char s1[512] = { 0 };
char userinput[40] = { 0 };
char symbol1[40] = { 0};
char finished_string[512] = { 0 };
printf("%s\n", rando(s1));
generated(userinput);
printf("%s", symbol(symbol1, s1, userinput, finished_string));
getch();
return 0;
}
char *rando(char rarray[])
{
int counter = 0;
int i = 0;
int l = 0;
while (counter <= 40 && rarray[i] != '/0'){
l = (rand() % 26) +'A';
rarray[i] = ("%c", l);
i++;
counter++;
if (counter == 40)
rarray[i] = '/0';
}
return rarray;
}
void *generated(char string1[])
{
char input[40] = {0};
int i = 0;
printf("Please enter a string of Uppercase letters.\n");
string1 = gets(input);
if (string1 != NULL)
{
if (input[i] >= 'A' && input[i] <= 'Z'){
puts("You entered \t");
puts(string1);
}
else
puts("Error please enter capital letters.");
}
}
char *symbol(char symb[], char rarray[], char string1[],char Farray[])
{
char input_symbol[40];
char symbol;
int count;
int i = 0;
printf("Please enter a character or symbol.\n");
symb = gets(input_symbol);
//puts(symb);
for (count = 0; count < 40 && Farray[i] != NULL; count++){
if (string1[i] == rarray[i]){
Farray[i] = string1[i];
Farray[i] = puts(symb);
i++;
}
else
{
Farray[i] = string1[i];
i++;
}
Farray[40] = '\0';
}
}