Hello all! I am hoping someone can help me with this because my professor wont get back to me(he lacks programming skills, I believe). Anyways, I am supposed to create an array with a user specified amount(between 10 and 30) of random letters to be generated. After the amount of characters has been specifed, the program should send the base address of that memory and its size to a random function(which I thought I created correctly) and fill the memory with random capital letters. After this function has completed, it will go back to the main program and prompt the user to enter a capital letter to be searched for(using the search function, which I also thought I did correctly). In the search function, it should print out the index locations of each and every match between the random letters and the letter being searched for. Hope it makes sense. I have provided the code that I have so far. Another thing, it is in 4 files: array.h, array.c, random.c, and search.c...I thank you for helping in advance!
Code:
/*array.h*/
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int random(char *data, int num);
int search(char *data, char ch, int num);
/*array.c*/
#include "array.h"
int main(void){
int num;
char ch;
char *data;
printf("%s%s",
"Enter the number of random letters to be generated \n",
"(MUST BE BETWEEN 10 AND 30): ");
scanf("%d", &num);
fflush (stdin);
while(num < 10 || num > 30){
printf("Error: Must be between 10 and 30! Try Again:\n");
scanf("%d", &num);
fflush (stdin);
}
data = calloc(num, sizeof(char));
int random(char *data, int num);
printf("Enter a CAPITAL LETTER to be searched for:\n");
scanf("%c", &ch);
while(!isupper(ch)){
printf("Error: Must be a capital letter, Try Again:\n");
scanf("%c", &ch);
}
int search(char *data, char ch, int num);
return 0;
}
/*random.c*/
#include "array.h"
int random(char *data, int num){
srand(time(NULL));
data[num] = (rand() % 26) + 65;
return 0;
}
/*search.c*/
#include "array.h"
int search(char *data, char ch, int num){
int n;
for(n = -1; n < num; ++n)
if(data[n] = ch)
printf("data[%d] = %c\n", data[n], ch);
return 0;
}