Hello I am new to coding and was just wandering why the below code:
#include <stdio.h>
int main() {
for(int i = 0; 1 ; i++) {
char x;
char z[1+i];
x=getchar();
if (x == '\n'){
*(z+i) = '\0';
printf("%s",z);
break;}
*(z+i) = x;
printf("%s, %d = %c, i = %d\n",z, (z+i),*(z+i),i);
}
return 0;
}
of C does not work for inputs that are more than 15 characters? (I don't think it is beacuse of the current state of my pc since I tried it with an online compiler and it still breaks at 16 chars, but then again I am new to coding.) Would appreciate any help. Thank you.
#include <stdio.h>
int main() {
for(int i = 0; 1 ; i++) {
char x;
char z[1+i];
x=getchar();
if (x == '\n'){
*(z+i) = '\0';
printf("%s",z);
break;}
*(z+i) = x;
printf("%s, %d = %c, i = %d\n",z, (z+i),*(z+i),i);
}
return 0;
}
of C does not work for inputs that are more than 15 characters? (I don't think it is beacuse of the current state of my pc since I tried it with an online compiler and it still breaks at 16 chars, but then again I am new to coding.) Would appreciate any help. Thank you.