All Questions
3 questions
-1
votes
3
answers
81
views
sizeof doesn't give back the real length of an input [duplicate]
I tried to test sizeof in my programm but it doesn't work.
char toFind[100];
fgets(toFind, sizeof(toFind), stdin);
printf(" %i", sizeof(toFind));
And what ever I put in it prints out 100.
...
-3
votes
2
answers
1k
views
Allocate char array and strings
I have problem understanding the code below.
What value index=strlen(strs[0]) gets?
char *a= malloc (sizeof(char)*(index+1)) Is this the standard way to allocate array for char array?
What does strs[...
1
vote
5
answers
700
views
C char array has different length than expected
I have a very simple code:
secret[]="abcdefgh";//this is declared in different function and is random word
int len=strlen(secret);//ofc it is 8 in this case
char word[len];
for(int a=0;a<len;a++){/...