What is the difference in the following? ( C )
char x[100] ;
char y[] = ""; // no space between the double quotations
char z[] = " "; // space between the double quotations
if the user entered an input for example "test" in the array y , does it's size changes to 5 ?
char y[] ="";
gets(y); // user entered "test"
and if user entered an input larger than 100 in the array x , does it's size changes ?
char x[100] ;
gets(x); // user entered an input larger than 100
and why this code works : ( if user entered "test" it will print "test" )
#include<stdio.h>
#include<string.h>
int main(){
char name[] = " " ; // space between the double quotations
gets(name);
for(int i=0 ; i< strlen(name) ; i++) {
printf("%c",name[i]);
}
return 0 ;
}
and this one doesn't ? ( this one prints strange symbols ) ( if user entered "test" it will print "t" and a smiley symbol )
#include<stdio.h>
#include<string.h>
int main(){
char name[] = "" ; // no space between the double quotations
gets(name);
for(int i=0 ; i< strlen(name) ; i++) {
printf("%c",name[i]);
}
return 0 ;
}
and this one makes me crazy , it worked without a loop , even with no space between double quotations
#include<stdio.h>
#include<string.h>
int main(){
char name[] = "" ; // no space between the double quotations
gets(name);
printf("%c",name[0]);
printf("%c",name[1]);
printf("%c",name[2]);
printf("%c",name[3]);
return 0 ;
}
and this one works using ( puts ) even with no space between double quotations :
#include<stdio.h>
#include<string.h>
int main(){
char name[] = "" ;
gets(name);
puts(name);
return 0 ;
}