How do I pass a vector to a function? Something that, in the Moon, would be like this:
vector = {"V", "e", "t", "o", "r"}
function getVector(vector, pos)
return vector[pos]
end
print(getVector(vector, 1))
Output: "V"
I tried this way:
#include <stdio.h>
void main() {
char vector[5] = {"V", "e", "t", "o", "r"};
char getVector(char vector[], int pos) {
return vector[pos];
}
printf("%c", getVector(vector, 0));
}
The errors:
G:\PROJETOS\C\test.c In function 'main':
3 5 G:\PROJETOS\C\test.c [Error] excess elements in char array initializer
3 5 G:\PROJETOS\C\test.c [Error] (near initialization for 'vector')
3 5 G:\PROJETOS\C\test.c [Error] excess elements in char array initializer
3 5 G:\PROJETOS\C\test.c [Error] (near initialization for 'vector')
3 5 G:\PROJETOS\C\test.c [Error] excess elements in char array initializer
3 5 G:\PROJETOS\C\test.c [Error] (near initialization for 'vector')
3 5 G:\PROJETOS\C\test.c [Error] excess elements in char array initializer
3 5 G:\PROJETOS\C\test.c [Error] (near initialization for 'vector')