This is my first time posting or really doing anything here on daniweb. I have read a lot of other posts and you all are very knowledgeable and respectful. So if I don't do something that I need to as per the forum regulations let me know. I have a question. I am writing a program for class that creates a basic vector function in c. It uses this vector function to dynamically expand an array to the size of the string that the user types in. My problem is when i call the function it says conflicting types for 'vector'. Can anyone help me with this problem. I have the code posted below.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int arraySize = 1;
int main(void){
int i, j;
int h = 0;
int index = 0;
char c;
char *array = (char *) calloc(arraySize, sizeof(char));
array[0] = '\0';
char ch[] = "HW6 Input: ";
printf("\nEnter a character to input in the string.\n");
printf("Only enter one character at a time and press enter after each character.\n");
printf("Press enter without a character to continue;\n");
while( (c = getc(stdin)) != '\n'){
array[index] = c;
index++;
if(index < arraySize){
char *tmp = (char*) calloc(arraySize, sizeof(char));
memcpy(tmp, array, arraySize);
*array = vector(array);
memcpy(array, tmp, arraySize);
}
}
arraySize++;
*array = vector(array);
index++;
array[index] = '\0';
char output[arraySize + 13];
for(i = 0; i < strlen(ch); i++){
output[i] = ch[i];
}
for(j = i; j < strlen(output); j++){
output[j] = array[h];
h++;
}
printf("\n%s\n", output);
free(array);
return 0;
}
char *vector(char *theArray){
arraySize++;
void *temp = (char *) calloc(arraySize, sizeof(char));
theArray = (char *) temp;
return theArray;
}
Thank you.