If(strcmp(str, "") == 0) - What does this line of code mean?

Joined
Aug 8, 2022
Messages
1
Reaction score
0
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);
}


}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top