Hi, I am a student and learning C programming. There two things I don't understand in this function:
"if(strcmp(str, "") == 0)" - what is the string compared to, what exactly does "" mean in this case and
strlen(str) + 1) - why is +1 counted?
Thank you!
void UserInput(char **arr, int *len)
{
char str[300];
for(int i = 0; i<300;++i)
{
if(fgets(str, 300, stdin) == NULL)
break;
str[strcspn(str, "\r\n")] = 0;
if(strcmp(str, "") == 0)
continue;
arr = strcpy((char *) malloc(sizeof(char) * strlen(str) + 1), str);
++(*len);
}
}
"if(strcmp(str, "") == 0)" - what is the string compared to, what exactly does "" mean in this case and
strlen(str) + 1) - why is +1 counted?
Thank you!
void UserInput(char **arr, int *len)
{
char str[300];
for(int i = 0; i<300;++i)
{
if(fgets(str, 300, stdin) == NULL)
break;
str[strcspn(str, "\r\n")] = 0;
if(strcmp(str, "") == 0)
continue;
arr = strcpy((char *) malloc(sizeof(char) * strlen(str) + 1), str);
++(*len);
}
}