7
How do I pass a vector to a function? Something that, on 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 so:
#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 mistakes:
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')
Did something go wrong in your code? The way it is, it should work...
– mgibsonbr
Yes, I edited the question, there are the mistakes.
– Gabriel Sales
Hehe looked at the function itself with so much focus that I didn’t pay attention to the code around... : P
– mgibsonbr