2
I just started learning the C programming language and I’m having a hard time.
I declare a string vector, pass values to that vector and then pass that same vector as a function argument. The problem is here, when I run the program and the moment I pass the array of strings as argument, it simply stops working.
I leave here an example of code, to see how I’m doing:
#include <stdio.h>
#include <stdlib.h>
void MostraTodos(char memoria[]);
int main(int argc, char *argv[]) {
char memoria[3][30];
int i;
for(i=0;i<3;i++){
printf("Introduza o seu nome\n");
scanf("%s", &memoria[i]);
}
MostraTodos(memoria);
return 0;
}
void MostraTodos(char memoria[]){
int i;
for(i=0; i<3; i++){
printf("%s", memoria[i]);
}
}
I’ve done a lot of research and I can’t find the answer, and I think it’s easy to solve.
Use as follows: scanf_s("%s", &memoria[i], 30);
– lsalamon