Hello!
I am writing some code for multiple purposes. I've already compiled the parts with the numeric arrays. The issues that I've been having are dealing with stringSpace(char name).
Here is my code:
Code:
#include <stdio.h>#include <stddef.h>
#include <stdlib.h>
void printArray(int n[]);
void randomPop(int array2[]);
void stringSpace(char name);
int main(void)
{
int i;
int n[4];
int array2[20];
char name[8] = "Serenity";
for (i = 0; i < 4; ++i) {
printf("Enter value %d. \n", i+1);
scanf("%d", &n[i]);
}
printf("%s%13s\n", "Element", "User's Value");
printArray(n);
printf("%s%13s\n", "Element", "Random Value");
randomPop(array2);
printf("%s", "Name with spaces: \n");
stringSpace(name);
return 0;
}
void printArray(int n[])
{
int i;
for (size_t i = 0; i < 4; ++i) {
printf("%7zu%13d\n", i, n[i]);
}
}
void randomPop(int array2[])
{
int j;
for (size_t j = 0; j < 20; ++j) {
array2[j] = rand() % 100 + 1;
printf("%7zu%13d\n", j, array2[j]);
}
}
void stringSpace(char name)
{
char m;
for (size_t m = 0; m < SIZE && name[m] != '\0'; ++m) {
printf("%c", name[m]);
}
I'm not quite sure how to go about this. I've been trying to follow an example from my C textbook, but it isn't leading me in the right place. In the example, the user is prompted for the characters, while I already have the characters, "Serenity," that I want to be printed.
Overall, I'm trying to print out the word, "Serenity," but with spaces between each letter: "S e r e n i t y."
I want to establish a prototype for this and call it from main.
Any help would be appreciated. The errors that I'm facing for the most part mostly include:
-note: expected ‘char’ but argument is of type ‘char *’
-error: subscripted value is neither array nor pointer nor vector
"Name" must be being read as a pointer, if I'm not mistaken. Is there a way to fix this? I'm trying to figure out how to initialize a character array but as a string.
Thanks for all help in advance. I really appreciate it.