In an assignment for class we have to ask the user how many characters they'd like to enter and then read the characters into an array of that size. I've had problems with calling a function to do this. I will also be passing this array to other functions, so I'm not sure if anything has to be modified either.
This is what I've done so far
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void Test(char, int);
int main()
{
char *text;
int i, size, *sizeptr;
sizeptr = &size;
Test(text, size);
for(i = 0; i < size; i++)
{
putchar(text[i]);
}
system("PAUSE");
return(0);
}
void Test(char *text, int *sizeptr)
{
int i;
printf("How many characters do you want to enter?\t");
scanf("%d", sizeptr);
text = (char*) malloc(*sizeptr * sizeof(char));
memset(text, 0, *sizeptr);
printf("Enter your text: (DO NOT INCLUDE SPACES)\n");
scanf("%s", text);
}