Character array in c with function -


i have problem character array in c program.

the program shutdown when run it. think problem somewhere passing character array in function.

here's code:

#include<stdio.h> #include<string.h> #define dagen 7  void inlezen(int[][dagen], char[][12]);  int main(void) {     int i;     int temp[1][dagen];      char dagen[7][12];      strcpy(dagen[0], "ma");     strcpy(dagen[1], "di");     strcpy(dagen[2], "woe");     strcpy(dagen[3], "do");     strcpy(dagen[4], "vr");     strcpy(dagen[5], "za");     strcpy(dagen[6], "zo");        inlezen(temp, 1, dagen, dagen, 7, 12);  }  void inlezen(int t[][dagen], char d[][12]) {     int i;      (i = 0; < dagen; i++)     {         printf("geef de temperatuur overdag van %s", d[i]);         scanf("%d%*c", &t[0][i]);     }     (i = 0; < dagen; i++)     {         printf("geef de temperatuur 's avonds van %s", d[i]);         scanf("%d%*c", &t[1][i]);     }  } 

i've edited code, still doesn't work.

in code

 strcpy(dagen[6], "zo"); 

you're accessing out of bound memory using 6 index value. definition of dagen

 char dagen[6][12]; 

only permits valid access 5 first index. ] using 6, invokes undefined behaviour.

fwiw, c uses 0 based indexing arrays.

that said, call

 inlezen(temp, 1, dagen, dagen, 6, 12); 

does not match function signature, @ all.

finally, scanf() family expects pointer variable type of arguments supplied format specifiers, so, the

  scanf("%d%*c", t[0][i]); 

statements should actually

  scanf("%d%*c", &t[0][i]); 

and likewise.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -