I need help in creating a function that will show the first letter of the actual word. It is to be considered however that the words are randomly selected from a text file and usage of break, continue exit and global functions are not allowed. For example if the actual word is tiger and the word is jumbled as rgeti, (for instance), I want the new function to display "The first letter of the actual word is t ". This is my current code void scramble(char *p) { int i = 0; int len=strlen(p) while(i < len) { int c1 = (rand() % (len)); int c2 = (rand() % (len)); if(c1 != c2) { p[c1] = p[c1] ^ p[c2]; p[c2] = p[c1] ^ p[c2]; p[c1] = p[c1] ^ p[c2]; i++; } } }
I have created a C function that jumbles the word. (shown below). I need help in creating a function that will show the first letter of the actual word. It is to be considered however that the words are randomly selected from a text file and usage of break, continue exit and global functions are not allowed.
For example if the actual word is tiger and the word is jumbled as rgeti, (for instance), I want the new function to display "The first letter of the actual word is t ".
This is my current code
void scramble(char *p)
{
int i = 0;
int len=strlen(p)
while(i < len)
{
int c1 = (rand() % (len));
int c2 = (rand() % (len));
if(c1 != c2)
{
p[c1] = p[c1] ^ p[c2];
p[c2] = p[c1] ^ p[c2];
p[c1] = p[c1] ^ p[c2];
i++;
}
}
}
Step by step
Solved in 2 steps with 1 images