Hello

can anyone help me with the following
The below will actually display the Name found part, even though no name actually exists and its just blank, how do i get round this, the string name will contain blanks, but i need to check if blank, then treat as blank.

char name[80]
   int len;
 
   strcpy(name, "                       " );
   len=strlen(name);
 
   if (len == 0 )
   {
 
        printf("No name....\n" );
   }
   else
   {
        printf("Name found...\n" );
   }

Recommended Answers

All 5 Replies

maybe something like this?

if name[0] = ' '
{
    printf("No name....\n" );
}

But this is setting the variable length to 0 bytes

what happens if there is actually a real values in name like

name=[80];

strcpy(name, "CHRISXHSHSHSHSH" );

excuse me, want I meant was:

if (name[0] == ' ')
{
    printf("No name....\n" );
}

I was busy doing a prog in basic so I messed up the syntax :rolleyes:

That wont work, and wont compile

Its an empty characters constant

What compiler are you using, because I use VS2005pro and it works fine with me:

int main(int argc, char *argv[])
{
 
char name[80];
 
strcpy(name, " " );
 
if (name[0] == ' ')
{
printf("No name....\n" );
}
else
{
printf("Name found...\n" );
}
getchar();
getchar();
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.