I'm trying to learn C, so while making some exercises I ran into a problem I can't understand.
I created a character array buf [100][100], in it I store some strings. Now i would like to change a certain string in to another one by using the strcpy command. But when trying to adress it with a integer (z) it does not want to work. however when i manually adress the array with a value it works as intended.
can anyone give me an explanation for this?
Thank you in advance, Sam
code :
int main() {
char buf [100][100];
int i=0,j=0;
int lijn;
int x,k;
int z;
char stringN [100];
FILE * fpointer = fopen("employees.txt","r");
if (!fpointer) { return 1; }
printf("regel nummer?:");
scanf("%d",z);
printf("nieuwe regel");
scanf("%s",stringN);
while(fgets(buf[i],100,fpointer)!=NULL){
i++;
j++;
}
strcpy(buf[z], stringN);
strcat(buf[z], "\n");
x=0;
for (k=j;k>=1;k--){
printf("%s",buf[x]);
x++;
}
return 0;
}