I'm creating a simple project to better understand pointers.
I'm trying to scanf some values into an array from a function and then printing them ...
but when i do, i get the correct words printed except for some symbols tact on to the end of the string... here is the code:
but when i enter this for instance:Code:void get_colors(char scanned[][], int n);
int main(void){
int n = 6, j, i;
char scanned[6][7];
char color[12][7];
char *pcolor;
char *pscanned;
/* Declare pointers to their arrays */
pcolor = &color[0][0];
pscanned = &scanned[0][0];
get_colors(pscanned, n);
for(j = 0; j<6; j++){
for(i = 0; i<7; i++){
printf("%c", scanned[j][i]);
} printf("\n");
}
getch();
return 0;
}
void get_colors(char scanned[6][7], int n){
printf("Please enter 6 resistor colors: \n");
scanf("%s %s %s %s %s %s", &scanned[0], &scanned[1], &scanned[2], &scanned[3], &scanned[4], &scanned[5]) ;
}
brown green orange yellow black green
the output looks like:
brown
green á <--- that ...?
orange
yellow
black
green
and any useful tips to getting my head around pointers would be AMAZING! Pointers are going to be the death of me! lol...
thanks in advance